comparison lib/ur/list.ur @ 1057:eaba663fd6aa

Represent FFI function names as strings, to deal with cross-file recursion
author Adam Chlipala <adamc@hcoop.net>
date Sat, 05 Dec 2009 14:01:34 -0500
parents 166ea3944b91
children 52571ca9b777
comparison
equal deleted inserted replaced
1056:c42bfbd75ca9 1057:eaba663fd6aa
19 | _ => False 19 | _ => False
20 in 20 in
21 mkEq eq' 21 mkEq eq'
22 end 22 end
23 23
24 fun foldl [a] [b] f = 24 fun foldl [a] [b] (f : a -> b -> b) =
25 let 25 let
26 fun foldl' acc ls = 26 fun foldl' acc ls =
27 case ls of 27 case ls of
28 [] => acc 28 [] => acc
29 | x :: ls => foldl' (f x acc) ls 29 | x :: ls => foldl' (f x acc) ls
30 in 30 in
31 foldl' 31 foldl'
32 end 32 end
33
34 val rev = fn [a] =>
35 let
36 fun rev' acc (ls : list a) =
37 case ls of
38 [] => acc
39 | x :: ls => rev' (x :: acc) ls
40 in
41 rev' []
42 end
43
44 fun foldr [a] [b] f (acc : b) (ls : list a) = foldl f acc (rev ls)
33 45
34 fun foldlAbort [a] [b] f = 46 fun foldlAbort [a] [b] f =
35 let 47 let
36 fun foldlAbort' acc ls = 48 fun foldlAbort' acc ls =
37 case ls of 49 case ls of
52 | _ :: ls => length' (acc + 1) ls 64 | _ :: ls => length' (acc + 1) ls
53 in 65 in
54 length' 0 66 length' 0
55 end 67 end
56 68
57 val rev = fn [a] =>
58 let
59 fun rev' acc (ls : list a) =
60 case ls of
61 [] => acc
62 | x :: ls => rev' (x :: acc) ls
63 in
64 rev' []
65 end
66
67 fun foldlMapAbort [a] [b] [c] f = 69 fun foldlMapAbort [a] [b] [c] f =
68 let 70 let
69 fun foldlMapAbort' ls' acc ls = 71 fun foldlMapAbort' ls' acc ls =
70 case ls of 72 case ls of
71 [] => Some (rev ls', acc) 73 [] => Some (rev ls', acc)