1(* 2 * util/list.sml -- some additional list utilities 3 * 4 * COPYRIGHT (c) 1997 by Martin Erwig. See COPYRIGHT file for details. 5 *) 6 7structure UList = 8struct 9 fun cons x l = x::l 10 11 fun remove x [] = [] 12 | remove x (y::l) = if x=y then remove x l else y::remove x l 13 14 fun select _ _ [] = [] 15 | select f p (x::l) = if p x then f x::select f p l else select f p l 16 17 exception NotFound 18 fun lookup _ [] = raise NotFound 19 | lookup x ((y,z)::l) = if x=y then z else lookup x l 20 21 local 22 fun scan (_,_,_,y,[]) = y 23 | scan (f,g,w,y,x::l) = 24 let val v=g x 25 in 26 if f (v,w) = w then 27 scan (f,g,w,y,l) 28 else 29 scan (f,g,v,x,l) 30 end 31 in 32 fun thatOne (f,g) l = 33 let val (x::l') = l in scan (f,g,g x,x,l') end 34 end 35end 36