Created
December 31, 2014 17:21
-
-
Save gsg/fdfe41d6c94f01677dd7 to your computer and use it in GitHub Desktop.
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
module Univ : sig | |
type t | |
val embed : unit -> ('a -> t) * (t -> 'a option) | |
end = struct | |
type t = unit ref * (unit -> unit) | |
let embed () = | |
let id = ref () in | |
let loc = ref None in | |
let put x = id, (fun () -> loc := Some x) in | |
let get (rid, rstore) = | |
if id != rid then None else begin | |
rstore (); | |
let r = !loc in | |
loc := None; r | |
end in | |
put, get | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment