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: v fun count_list2 f = List.foldl (fn (hd,acc) => (if f hd then 1 else 0) + acc) 0 val count_zeroes_7 = count_list2 (fn x => x=0) v val count_zeroes_7' = count_list2 (curry (op=) 0) v (************) ( (** Examples for understanding type inference **) ( fun f x = let val (y,z) = x in (abs y) + z end fun sum lst = case lst of => 0 | hd::tl => hd + (sum tl) fun length lst = case lst of => 0 | hd::tl => 1 + (length tl) fun compose (f,g) = fn x => f (g x) f (***********) ( (** Simple use of modules for namespace management **) ( signature MATHLIB = sig val fact : int -> int val half_pi : real val doubler : int -> int end e structure MyMathLib :> MATHLIB = struct fun fact x = if x=0 then 1 else x * fact (x - 1) val half_pi = Math.pi / 2.0 v fun doubler y = y + y end e val pi = MyMathLib.half_pi + MyMathLib.half_pi v val twenty_eight = MyMathLib.doubler 14...
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