Skip to content

Instantly share code, notes, and snippets.

@mohanr
Last active December 6, 2016 07:26
Show Gist options
  • Save mohanr/95fb9c47a1f247f3f381a9ac08269795 to your computer and use it in GitHub Desktop.
Save mohanr/95fb9c47a1f247f3f381a9ac08269795 to your computer and use it in GitHub Desktop.
Associative List
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