uris77
8/5/2014 - 2:48 PM

Example ML: finds all strings in a list that match full_name.

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