Created
July 26, 2019 11:19
-
-
Save zindel/4ce0770c8dac36f36d4876a47e685305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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