Skip to content

Instantly share code, notes, and snippets.

@uris77
Created August 5, 2014 14:48
Show Gist options
  • Save uris77/26a07134860337455c2a to your computer and use it in GitHub Desktop.
Save uris77/26a07134860337455c2a to your computer and use it in GitHub Desktop.
Example ML: finds all strings in a list that match full_name.
(* I may be wrong. I'm still an ML newbie. *)
(* Example of something that does not require a unit test. This will only compile of the types align. Traditional TDD is a little *)
(* difficult to do with this. However, I think QuickCheck tests are more suited since it is purely functional. *)
fun similar_names(lst, full_name) =
let val {first=first_name, middle=middle_name, last=last_name} = full_name
in
let fun arrange(lst', acc) =
case lst' of
[] => acc
|x::xs => arrange(xs, {first=x, middle=middle_name, last=last_name}::acc)
in
full_name::rev(arrange(get_substitutions2(lst, first_name), []))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment