Last active
April 9, 2018 21:27
-
-
Save cls/ec4b45aff9b41ed80bf98061a4b2c2d8 to your computer and use it in GitHub Desktop.
Higher-order relabelling function, ported from OCaml to Standard ML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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