Skip to content

Instantly share code, notes, and snippets.

@gsg
Created December 31, 2014 17:21
Show Gist options
  • Save gsg/fdfe41d6c94f01677dd7 to your computer and use it in GitHub Desktop.
Save gsg/fdfe41d6c94f01677dd7 to your computer and use it in GitHub Desktop.
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