Advertisement
Guest User

Untitled

a guest
Oct 5th, 2013
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.76 KB | None | 0 0
  1. module Exam2011
  2.  
  3. type name = string
  4. type phone = int
  5. type level = int
  6.  
  7. type description = phone * level
  8. type register = (phone * description) list
  9.  
  10. let reg = [("Joe",(10101010,4));
  11.            ("Sal",(11111111,2));
  12.            ("Sam",(12121212,7));
  13.            ("Jane",(13131313,1))]
  14.  
  15. let rec getPhone n r =
  16.   match r with
  17.   | [] -> failwith "Register"
  18.   | (n', (p,_))::xs -> if n = n' then p else getPhone n xs
  19.  
  20. let delete = function
  21.   | (n,r) -> List.foldBack (fun acc e ->
  22.                               match e with
  23.                               | (n', _) -> if n=n' then acc else e :: acc) r []
  24.  
  25. let getCandidates le r =
  26.   List.fold
  27.     (fun acc r' ->
  28.      match r' with
  29.       | (n,(p,le')) when abs(le-le') < 3 -> (n,p)::acc
  30.       | _ -> acc) [] r
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement