Created
August 5, 2014 14:48
-
-
Save uris77/26a07134860337455c2a to your computer and use it in GitHub Desktop.
Example ML: finds all strings in a list that match full_name.
This file contains hidden or 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
(* 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