Histogramm erstellen OCaml

Meine Aufgabe besteht darin, ein Histogramm zu erstellen, das angibt, wie oft ein Element in einer Liste enthalten ist.

Input:[2;2;2;3;4;4;1]
Output[(2, 3); (2, 2); (2, 1); (3, 1); (4, 2); (4, 1); (1, 1)]  
Expected output : [(2, 3); (3, 1); (4, 2); (1, 1)]

My code:

let rec count a ls = match ls with
  |[]              -> 0
  |x::xs  when x=a -> 1 + count a xs
  |_::xs           -> count a xs

let rec count a = function
  |[]              -> 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)] @ histo xs ;;

Was habe ich falsch gemacht

Antworten auf die Frage(2)

Ihre Antwort auf die Frage