Oh, FFS! How come I never thought of this

module Univ : Univ = struct
type t = {
id : unit ref;
store : unit -> unit;
}
 
let embed () =
let id = ref () in
let r = ref None in
let put a =
let o = Some a in
{ id = id; store = (fun () -> r := o); }
in
let get t =
if id == t.id then (t.store (); let a = !r in r := None; a) else None
in
(put, get)
end

posted : Monday, March 10th, 2008

tags :