This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: fun map (f,l) = case l of => | fst::rest => (f fst)::(map(f,rest)) (* This fold function is at least as useful *) fun fold (f,acc,l) = case l of => acc | fst::rest => fold (f, f(acc,fst), rest) (* fold is actually in ML's standard library as List.foldl, but List.foldl is "curried" (explanation soon). You will use List.foldl in homework 3 *) (* Example uses that do not use private data *) ( fun f3 l = fold ((fn (x,y) => x+y), 0, l) f fun f4 l = fold ((fn (x,y) => x andalso y >= 0), true, l) f (* Examples that use that uses private data *) ( fun f5 (l,lo,hi) = fold ((fn (x,y) => if y >= lo andalso y <= hi then x+1 else x), 0, l) fun f6 (lst,hi) = map((fn x => if x > hi then hi else x), lst)...
View Full Document
This note was uploaded on 10/12/2009 for the course CSE 341 taught by Professor Staff during the Spring '08 term at University of Washington.
- Spring '08