Skip to content

Instantly share code, notes, and snippets.

@cls
Last active April 9, 2018 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cls/ec4b45aff9b41ed80bf98061a4b2c2d8 to your computer and use it in GitHub Desktop.
Save cls/ec4b45aff9b41ed80bf98061a4b2c2d8 to your computer and use it in GitHub Desktop.
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