Skip to content

Instantly share code, notes, and snippets.

@zindel
Created July 26, 2019 11:19
Show Gist options
  • Save zindel/4ce0770c8dac36f36d4876a47e685305 to your computer and use it in GitHub Desktop.
Save zindel/4ce0770c8dac36f36d4876a47e685305 to your computer and use it in GitHub Desktop.
module IntMap = Map.Make(struct type t = int let compare = compare end)
let hello () =
let input = [1;2;3;4;4;5;100;100;1;2] in
let counts =
List.fold_left (fun map n -> IntMap.update n (
function
| None -> Some 1
| Some c -> Some (c + 1)
) map)
IntMap.empty
input
in
counts
|> IntMap.bindings
|> List.iter (fun (key, count) -> Printf.printf "[%d] = %d\n" key count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment