Mercurial > urweb
comparison src/list_util.sml @ 849:e571fb150a9f
Fix a bug in type class enrichment from substructures
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 16 Jun 2009 14:38:01 -0400 |
parents | 0f7e2cca6d9b |
children |
comparison
equal
deleted
inserted
replaced
848:e8594cfa3236 | 849:e571fb150a9f |
---|---|
121 end | 121 end |
122 in | 122 in |
123 fm ([], s) | 123 fm ([], s) |
124 end | 124 end |
125 | 125 |
126 fun foldlMapiPartial f s = | |
127 let | |
128 fun fm (n, ls', s) ls = | |
129 case ls of | |
130 nil => (rev ls', s) | |
131 | h :: t => | |
132 let | |
133 val (h', s') = f (n, h, s) | |
134 val ls' = case h' of | |
135 NONE => ls' | |
136 | SOME h' => h' :: ls' | |
137 in | |
138 fm (n + 1, ls', s') t | |
139 end | |
140 in | |
141 fm (0, [], s) | |
142 end | |
143 | |
126 fun foldlMapAbort f s = | 144 fun foldlMapAbort f s = |
127 let | 145 let |
128 fun fm (ls', s) ls = | 146 fun fm (ls', s) ls = |
129 case ls of | 147 case ls of |
130 nil => SOME (rev ls', s) | 148 nil => SOME (rev ls', s) |
166 let | 184 let |
167 fun m i acc ls = | 185 fun m i acc ls = |
168 case ls of | 186 case ls of |
169 [] => rev acc | 187 [] => rev acc |
170 | h :: t => m (i + 1) (f (i, h) :: acc) t | 188 | h :: t => m (i + 1) (f (i, h) :: acc) t |
189 in | |
190 m 0 [] | |
191 end | |
192 | |
193 fun mapiPartial f = | |
194 let | |
195 fun m i acc ls = | |
196 case ls of | |
197 [] => rev acc | |
198 | h :: t => | |
199 m (i + 1) (case f (i, h) of | |
200 NONE => acc | |
201 | SOME v => v :: acc) t | |
171 in | 202 in |
172 m 0 [] | 203 m 0 [] |
173 end | 204 end |
174 | 205 |
175 fun appi f = | 206 fun appi f = |