COMP 302 Study Guide - Final Guide: Currying

374 views25 pages

Document Summary

| fun combine f [] (y::ys) = raise listsunequal. | fun combine f (x::xs) [] = rais listsunequal. |combine f (x::xs) (y::ys) = (f(x,y)) :: (combine f xs ys) | prod(h::t) = h * prod(t) fun prod"([], acc) = acc. | prod"(h::t, acc) = prod"(t, h * acc) Prove that for any list l, prod(l) = prod"(l, 1) Use the lemma, prod(l) * acc = prod"(l, acc) Base case: l = [] prod([]) * acc = acc prod"([], acc) = acc. Suppose prod(h::t) * acc = prod"(h::t, acc) prod(h::t) * acc = h * prod(t) * acc. Using the filter function, write a function which takes as its input two lists and returns a list containing the intersection of the two list. Intersection [1,2,3,4] [1,4,5]; val it = [1,4] : int list solution: fun intersection [] l2 = [] Consider the following two programs for multiplying all the elements of a list t ogether.

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