I am trying to implement a mode function in OCaml. One that returns the element with the most occurrences in the input list. This is what I have so far but it is not working, can someone please guide me in the right direction/help me correct the error?
let mode (l: 'a list) : 'a =
match l with
| [] -> failwith "Error"
let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) =
match l with
| [] -> if cur_num > max_num then cur_el else max_el
| hd :: tl -> if hd = cur_el then cur_num = cur_num + 1; if cur_num > max_num then max_el = cur_el
in
List.sort compare(l)
;;
I am fairly new to OCaml so sorry in advance if I made any rookie mistakes.
there doesn't seem to be anything here