COP 4555 Lecture 3: COP4555 HW3 Solutions

159 views2 pages
4 Jun 2015
School
Course
Professor

Document Summary

> interleave_rev ([1;2;3], [4;5;6]);; val it : int list = [3; 6; 2; 5; 1; 4] //interleave two lists let rec interleave = function. | ( x :: xs , y :: ys ) -> x :: y :: interleave ( xs , ys) //reverse and interleave xs and ys let interleave_rev ( xs , ys ) = interleave ( list . rev xs , list . rev ys );; Problem 2 (5 points) write a curried f# function cartesian xs ys that takes as input two lists xs and ys and returns a list of pairs that represents the cartesian product of xs and ys . (the pairs in the cartesian product may appear in any order. > cartesian ["a";"b";"c"] [1;2;3];; val it : (char * int) list = [("a", 1); ("a", 2); ("a", 3); ("b", 1); ("b", 2); ("b", 3); ("c", 1); ("c", 2); ("c", 3)]

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents