Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Exercise 4.23
- type Person = {name : string; phoneNo : string; sex : string;
- yearOfBirth : int; themesOfInterest : string list}
- let john = {name = "John Smith"; phoneNo = "12345678"; sex = "M";
- yearOfBirth = 1964; themesOfInterest = ["Running"; "Outdoors"]};;
- let betty = {name = "Betty Jones"; phoneNo = "43834221"; sex = "F";
- yearOfBirth = 1966; themesOfInterest = ["Outdoors"; "Cars"; "Cooking"]};;
- let sue = {name = "Sue Jensen"; phoneNo = "87654321"; sex = "F";
- yearOfBirth = 1972; themesOfInterest = ["Running"; "Movies"]};;
- let tom = {name = "Tom Cruise"; phoneNo = "99999999"; sex = "M";
- yearOfBirth = 1978; themesOfInterest = ["Danger"; "Scientology"; "Movies"]};;
- let marcy = {name = "Marcy Runkle"; phoneNo = "31763299"; sex = "F";
- yearOfBirth = 1987; themesOfInterest = ["Danger"; "SM"; "Bald guys"]};;
- let krener = {name = "Svendstorp-Krener"; phoneNo = "28308120"; sex = "M";
- yearOfBirth = 1996; themesOfInterest = ["Games"; "Movies"; "Drinking"; "Girls"]};;
- let rec testInterest(p1s, p2s) =
- match (p1s,p2s) with
- | ([],_) -> false;
- | (p1::p1tail, p2s) -> if List.contains p1 p2s then true
- else testInterest(p1tail,p2s);;
- let rec isMatch(x, ps) =
- match (x,ps) with
- | (_, []) -> []
- | (x, p::tail) when abs(x.yearOfBirth - p.yearOfBirth) <= 10 && x.sex <> p.sex && testInterest(x.themesOfInterest, p.themesOfInterest) -> p::isMatch(x, tail)
- | (_, p::tail) -> isMatch(x, tail);;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement