Skip to content

Instantly share code, notes, and snippets.

@mohanr mohanr/letter.ml
Last active Dec 6, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.