Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.55 KB | None | 0 0
  1. // Exercise 4.23
  2. type Person = {name : string; phoneNo : string; sex : string;
  3.                yearOfBirth : int; themesOfInterest : string list}
  4.  
  5. let john = {name = "John Smith"; phoneNo = "12345678"; sex = "M";
  6.               yearOfBirth = 1964; themesOfInterest = ["Running"; "Outdoors"]};;
  7. let betty = {name = "Betty Jones"; phoneNo = "43834221"; sex = "F";
  8.              yearOfBirth = 1966; themesOfInterest = ["Outdoors"; "Cars"; "Cooking"]};;
  9. let sue = {name = "Sue Jensen"; phoneNo = "87654321"; sex = "F";
  10.               yearOfBirth = 1972; themesOfInterest = ["Running"; "Movies"]};;
  11. let tom = {name = "Tom Cruise"; phoneNo = "99999999"; sex = "M";
  12.               yearOfBirth = 1978; themesOfInterest = ["Danger"; "Scientology"; "Movies"]};;
  13. let marcy = {name = "Marcy Runkle"; phoneNo = "31763299"; sex = "F";
  14.               yearOfBirth = 1987; themesOfInterest = ["Danger"; "SM"; "Bald guys"]};;
  15. let krener = {name = "Svendstorp-Krener"; phoneNo = "28308120"; sex = "M";
  16.               yearOfBirth = 1996; themesOfInterest = ["Games"; "Movies"; "Drinking"; "Girls"]};;
  17.  
  18. let rec testInterest(p1s, p2s) =
  19.     match (p1s,p2s) with
  20.     | ([],_) -> false;
  21.     | (p1::p1tail, p2s) -> if List.contains p1 p2s then true
  22.                                   else testInterest(p1tail,p2s);;
  23.  
  24. let rec isMatch(x, ps) =
  25.     match (x,ps) with
  26.     | (_, []) -> []
  27.     | (x, p::tail) when abs(x.yearOfBirth - p.yearOfBirth) <= 10 && x.sex <> p.sex && testInterest(x.themesOfInterest, p.themesOfInterest) -> p::isMatch(x, tail)
  28.     | (_, p::tail) -> isMatch(x, tail);;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement