Last active
December 6, 2016 07:26
-
-
Save mohanr/95fb9c47a1f247f3f381a9ac08269795 to your computer and use it in GitHub Desktop.
Associative List
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
let insert l a = | |
if List.mem_assoc a l | |
then | |
let n = List.assoc a l in (a, n+1)::(List.remove_assoc a l) | |
else (a, 1)::l | |
let letters (word : string) : char MultiSet.t = | |
let rec insert (l : char MultiSet.t) (c : string) (i : int) : char MultiSet.t = | |
if ( String.length c > 1 ) then | |
insert ( MultiSet.insert l (String.get c i) ) ( String.sub c 1 ((String.length c) - 1) ) 0 | |
else | |
MultiSet.insert l (String.get c 0) | |
in insert MultiSet.empty word 0 | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment