From: Olivier A. <ol...@us...> - 2003-02-27 20:06:18
|
Eric C. Cooper [Thursday 27 February 2003] : > > On Thu, Feb 27, 2003 at 05:00:49PM +0100, Michal Moskal wrote: > > On Thu, Feb 27, 2003 at 02:51:58PM +0100, Stefano Zacchiroli wrote: > > > (* given a 'a option returns the 'a value if it's Some _ or raise an > > > exception, find a better name! *) > > > - val unsome : 'a option -> 'a > > > > Isn't this called valOf in SML? But unsome sounds better to me. > > This might not be to everyone's tastes, but I often use a related > function that I call "the": > val the : 'a option ref -> 'a > which fails with Failure "uninitialized variable" when the > (dereferenced) option is None. I use something like this too : ,----[ uref.ml ] | exception Uninitialised | type 'a uref = 'a option ref | let uref () = ref None | let (&=) r v = r := Some v | let is_init r = !r <> None | let (!!) r = | match !r with | | None -> raise Uninitialised | | Some v -> v `---- ,----[ uref.mli ] | exception Uninitialised | type 'a uref = 'a option ref | val uref : unit -> 'a uref | val ( &= ) : 'a uref -> 'a -> unit | val is_init : 'a uref -> bool | val ( !! ) : 'a uref -> 'a `---- -- Olivier |