error using List.filter OCaml -
hy, i'm trying create histogram keep getting error.
histogram example: input :[2;1;2;3;2;1;2;2;5] output :[(2,5);(1,2);(3,1);(5,1)] my code:
let rec count ls = match ls |[] -> 0 |x::xs when x=a -> 1 + count xs |_::xs -> count xs let rec histo l = match l |[] -> [] |x :: xs -> [(x, count x l)] @ list.filter(fun x -> xs != x)histo xs;; error: function has type ('a -> bool) -> 'a list -> 'a list applied many arguments; maybe forgot `;'.
you @ end ;) hints :
- take care of parenthesis (some missing in code).
- your filter not correct : (fun (t,_) -> not (t = x)) because histo returns list of tuple.
Comments
Post a Comment