comparison lib/ur/list.ur @ 846:0d30e6338c65

Some standard library reorgs and additions; handle mutual datatypes better in Specialize
author Adam Chlipala <adamc@hcoop.net>
date Tue, 09 Jun 2009 18:11:59 -0400
parents 6725d73c3c31
children 1c2f335297b7
comparison
equal deleted inserted replaced
845:6725d73c3c31 846:0d30e6338c65
8 | x :: ls => show x ^ " :: " ^ show' ls 8 | x :: ls => show x ^ " :: " ^ show' ls
9 in 9 in
10 mkShow show' 10 mkShow show'
11 end 11 end
12 12
13 val eq = fn [a] (_ : eq a) =>
14 let
15 fun eq' (ls1 : list a) ls2 =
16 case (ls1, ls2) of
17 ([], []) => True
18 | (x1 :: ls1, x2 :: ls2) => x1 = x2 && eq' ls1 ls2
19 | _ => False
20 in
21 mkEq eq'
22 end
23
13 fun foldl [a] [b] f = 24 fun foldl [a] [b] f =
14 let 25 let
15 fun foldl' acc ls = 26 fun foldl' acc ls =
16 case ls of 27 case ls of
17 [] => acc 28 [] => acc
18 | x :: ls => foldl' (f x acc) ls 29 | x :: ls => foldl' (f x acc) ls
19 in 30 in
20 foldl' 31 foldl'
32 end
33
34 fun foldlPartial [a] [b] f =
35 let
36 fun foldlPartial' acc ls =
37 case ls of
38 [] => Some acc
39 | x :: ls =>
40 case f x acc of
41 None => None
42 | Some acc' => foldlPartial' acc' ls
43 in
44 foldlPartial'
21 end 45 end
22 46
23 val rev = fn [a] => 47 val rev = fn [a] =>
24 let 48 let
25 fun rev' acc (ls : list a) = 49 fun rev' acc (ls : list a) =