This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: fun unzip3 lst = case lst of => (,,) | (a,b,c)::tl => let val (l1,l2,l3) = unzip3(tl) in (a::l1,b::l2,c::l3) end e (* another elegant use of "deep" patterns (even better with 'as' pattern) *) fun nondecreasing intlist = case intlist of => true | x:: => true | hd::(next::tl) => (hd <= next andalso nondecreasing (next::tl)) (* nested pattern-matching often convenient even without recursion; also the wildcard pattern is good style matche on a pair and one or more parts of it very useful on homework 2 *) datatype sign = P | N | Z d fun multsign (x1,x2) = let fun sign x = if x=0 then Z else if x>0 then P else N in case (sign x1,sign x2) of (Z,_) => Z | (_,Z) => Z | (P,P) => P | (N,N) => P | _ => N (* many say bad style; I am okay with it *) end...
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