Mercurial > urweb
comparison lib/ur/list.ur @ 850:1c2f335297b7
Fix a variable capture bug in nested JavaScript; some more list stuff
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 16 Jun 2009 17:52:44 -0400 |
parents | 0d30e6338c65 |
children | ed06e25c70ef |
comparison
equal
deleted
inserted
replaced
849:e571fb150a9f | 850:1c2f335297b7 |
---|---|
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 | 33 |
34 fun foldlPartial [a] [b] f = | 34 fun foldlAbort [a] [b] f = |
35 let | 35 let |
36 fun foldlPartial' acc ls = | 36 fun foldlAbort' acc ls = |
37 case ls of | 37 case ls of |
38 [] => Some acc | 38 [] => Some acc |
39 | x :: ls => | 39 | x :: ls => |
40 case f x acc of | 40 case f x acc of |
41 None => None | 41 None => None |
42 | Some acc' => foldlPartial' acc' ls | 42 | Some acc' => foldlAbort' acc' ls |
43 in | 43 in |
44 foldlPartial' | 44 foldlAbort' |
45 end | 45 end |
46 | 46 |
47 val rev = fn [a] => | 47 val rev = fn [a] => |
48 let | 48 let |
49 fun rev' acc (ls : list a) = | 49 fun rev' acc (ls : list a) = |
52 | x :: ls => rev' (x :: acc) ls | 52 | x :: ls => rev' (x :: acc) ls |
53 in | 53 in |
54 rev' [] | 54 rev' [] |
55 end | 55 end |
56 | 56 |
57 fun foldlMapAbort [a] [b] [c] f = | |
58 let | |
59 fun foldlMapAbort' ls' acc ls = | |
60 case ls of | |
61 [] => Some (rev ls', acc) | |
62 | x :: ls => | |
63 case f x acc of | |
64 None => None | |
65 | Some (x', acc') => foldlMapAbort' (x' :: ls') acc' ls | |
66 in | |
67 foldlMapAbort' [] | |
68 end | |
69 | |
57 val revAppend = fn [a] => | 70 val revAppend = fn [a] => |
58 let | 71 let |
59 fun ra (ls : list a) acc = | 72 fun ra (ls : list a) acc = |
60 case ls of | 73 case ls of |
61 [] => acc | 74 [] => acc |