From: Nicolas C. <war...@fr...> - 2003-02-28 02:45:30
|
> > > > (* 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 : > I also have mine, but in a different way ( that's "named" globals - better debug & type abstraction ) But since I hasn't used it much, I was wondering if it should be part of the ExtLib, maybe ? exception Global_not_initialized of string module Global : sig type 'a t val empty : string -> 'a t (* returns an new named empty global *) val name : 'a t -> string (* retrieve the name of a global *) val set : 'a t -> 'a -> unit (* set the global value contents *) val get : 'a t -> 'a (* get the global value contents - raise Global_not_initialized if not defined *) val undef : 'a t -> unit (* reset the global value contents to undefined *) val isdef : 'a t -> bool (* tell if the global value has been set *) val opt : 'a t -> 'a option (* return None if the global is undefined, or Some v where v is the current global value contents *) end Nicolas Cannasse |