equal
deleted
inserted
replaced
222 |
222 |
223 (*last element of a list*) |
223 (*last element of a list*) |
224 fun last_elem [] = raise LIST "last_elem" |
224 fun last_elem [] = raise LIST "last_elem" |
225 | last_elem [x] = x |
225 | last_elem [x] = x |
226 | last_elem (_ :: xs) = last_elem xs; |
226 | last_elem (_ :: xs) = last_elem xs; |
|
227 |
|
228 (*rear decomposition*) |
|
229 fun split_last [] = raise LIST "split_last" |
|
230 | split_last [x] = ([], x) |
|
231 | split_last (x :: xs) = apfst (cons x) (split_last xs); |
|
232 |
227 |
233 |
228 (*find the position of an element in a list*) |
234 (*find the position of an element in a list*) |
229 fun find (x, ys) = |
235 fun find (x, ys) = |
230 let fun f (y :: ys, i) = if x = y then i else f (ys, i + 1) |
236 let fun f (y :: ys, i) = if x = y then i else f (ys, i + 1) |
231 | f (_, _) = raise LIST "find" |
237 | f (_, _) = raise LIST "find" |