Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 518

How to write a function to count the number of elements in a list using a Map?

$
0
0
module IntMap = Map.Make(struct type t = int let compare = compare end)let rec count_with_map (il: int list) =  match il with  | [] -> []  | head :: tail ->    match count_with_map tail with    | (c, n) :: tail when head = n -> (head, n + 1) :: tail    | tail -> (head, 1) :: tail ;;

I think this is right but I kept getting this error.

Error: This expression has type (int * int) list       but an expression was expected of type 'a Count_with_map.IntMap.t

Viewing all articles
Browse latest Browse all 518

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>