1
Hy,我想創建一個直方圖,但我不斷收到錯誤。錯誤使用List.filter OCaml
Histogram example:
input :[2;1;2;3;2;1;2;2;5]
output :[(2,5);(1,2);(3,1);(5,1)]
我的代碼:
let rec count a ls = match ls with
|[] -> 0
|x::xs when x=a -> 1 + count a xs
|_::xs -> count a xs
let rec histo l = match l with
|[] -> []
|x :: xs -> [(x, count x l)] @ List.filter(fun x -> xs != x)histo xs;;
錯誤: 這個函數的類型是( 'A - >布爾) - >' 列表 - >「它是適用於太多的參數列表;也許你忘了';'。
'List.filter(有趣X! - > XS = X)(HISTO XS)' – beoliver