Version française
Home     About     Download     Resources     Contact us    
Browse thread
Option functions (or lack thereof) + operator for composition
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Allsopp <dra-news@m...>
Subject: RE: [Caml-list] Option functions (or lack thereof) + operator for composition
Serge Le Huitouze wrote:
> 1. Option type
> ****************
> It seems that there is no predefined function to test an "'a option" for
> being specifically "None" or "Some _". This seems to be confirmed by the
> very existence of:
> http://ocaml-lib.sourceforge.net/doc/Option.html
> which defines such functions ("is_none" and "is_some").
> I found it weird to be forced to use "match" expressions in my code for
> doing that, e.g.:
> *  let curSelectedRow = ref None in
> *  let updateButtonsStatus () =
> *      button_remove#misc#set_sensitive
> *              (match !curSelectedRow with None -> false | _ -> true)
> *  in
> *  ...
> 
> I could add the OCaml library mentioned above, but I don't know how to do
> it (and where to find it) and, since my code is supposed to go into some
> other code, I'd prefer avoiding adding yet another dependency to it...

ExtLib is well-worth having and it's very easy to install (just run ocaml install.ml in its source tree - findlib recommended but I've got a feeling that it can install without findlib as well). It's also very stable, feature-wise, so you're not really adding a tricky dependency. It's now hosted on Google Code at http://code.google.com/p/ocaml-extlib/downloads/list

You might also take a look at the batteries project (http://batteries.forge.ocamlcore.org) which I believe includes most if not all of ExtLib.



David