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: val true3 = inorder3_tupled(4,5,6) v fun is_nonnegative1 x = inorder3 0 0 x f val is_nonnegative2 = inorder3 0 0 v fun fold f = fn acc => fn l => case l of => acc | hd::tl => fold f (f(acc,hd)) tl fun sum1 l = fold (fn (x,y) => x+y) 0 l f val sum2 = fold (fn (x,y) => x+y) 0 v fun fold_with_sugar f acc l = case l of => acc | hd::tl => fold_with_sugar f (f(acc,hd)) tl fun exists predicate lst = case lst of => false | hd::tl => predicate hd orelse exists predicate tl fun other_curry1 f = fn x => fn y => f y x fun other_curry2 f x y = f y x fun curry f x y = f (x,y) fun uncurry f (x,y) = f x y f (* code describing our callback example *) ( val cbs : (int -> unit) list ref = ref fun onKeyEvent f = cbs := f::(!cbs) fun on_event i = let fun loop l = case l of => () | f::tl => (f i; loop tl) in loop (!cbs) end...
View Full Document
- Spring '08