1. camlspotter
  2. spotlib

Commits

camlspotter  committed 2286e1b

once

  • Participants
  • Parent commits ab746f6
  • Branches default

Comments (0)

Files changed (3)

File lib/OMakefile

View file
  • Ignore whitespace
    xgc
    spot
    uniqueID
+   once
 
 LIB = spotlib
 

File lib/once.ml

View file
  • Ignore whitespace
+type 'a t = 'a option ref
+
+let create () = ref None
+
+exception Already_initialized
+
+let set x v = match !x with
+  | Some _ -> raise Already_initialized
+  | None -> x := Some v
+
+let get x = !x

File lib/once.mli

View file
  • Ignore whitespace
+type 'a t
+
+exception Already_initialized
+
+val create : unit -> 'a t
+
+val set : 'a t -> 'a -> unit
+(** Raises Already_initialized when already set *)
+
+val get : 'a t -> 'a option
+