Mercurial > urweb
comparison lib/ur/list.ur @ 822:d4e811beb8eb
fn-pattern code in but not tested yet; hello compiles
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 28 May 2009 10:16:50 -0400 |
parents | 395a5d450cc0 |
children | 78504d97410b |
comparison
equal
deleted
inserted
replaced
821:395a5d450cc0 | 822:d4e811beb8eb |
---|---|
81 [] => rev acc | 81 [] => rev acc |
82 | x :: ls => fil (if f x then x :: acc else acc) ls | 82 | x :: ls => fil (if f x then x :: acc else acc) ls |
83 in | 83 in |
84 fil [] | 84 fil [] |
85 end | 85 end |
86 | |
87 fun exists (a ::: Type) f = | |
88 let | |
89 fun ex ls = | |
90 case ls of | |
91 [] => False | |
92 | x :: ls => | |
93 if f x then | |
94 True | |
95 else | |
96 ex ls | |
97 in | |
98 ex | |
99 end | |
100 | |
101 fun foldlMap (a ::: Type) (b ::: Type) (c ::: Type) f = | |
102 let | |
103 fun fold ls' st ls = | |
104 case ls of | |
105 [] => (rev ls', st) | |
106 | x :: ls => | |
107 case f x st of | |
108 (y, st) => fold (y :: ls') st ls | |
109 in | |
110 fold [] | |
111 end |