Higher-order relabelling function, ported from OCaml to Standard ML
exception NotFound | |
fun mk_idmap (mk_id : unit -> 'b) : ''a list -> ''a -> 'b = | |
foldl | |
(fn (x, acc) => | |
let val new_id = mk_id () in | |
fn id => if id = x then new_id else acc id | |
end) | |
(fn _ => raise NotFound) | |
val mk_id : unit -> int = | |
let val id = ref 0 in | |
fn () => (id := !id + 1; !id) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment