Browse thread
Re: [Caml-list] Option functions (or lack thereof) + operator for composition
-
Thomas Gazagnaire
-
Gabriel Kerneis
- Martin Jambon
-
Gabriel Kerneis
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin.jambon@e...> |
| Subject: | Re: [Caml-list] Option functions (or lack thereof) + operator for composition |
On 11/16/10 03:51, Gabriel Kerneis wrote: > On Tue, Nov 16, 2010 at 12:43:30PM +0100, Thomas Gazagnaire wrote: >> You are not forced to use match expression, you can just define : >> let is_none x = match x with None -> true | Some _ -> false >> and is_some x = not (is_none x) >> and then use these functions in your code ... > > Or even simpler: > let is_none = (=) None > let is_some = (!=) None > Note that you can use this directly, for instance: > List.filter ((!=) None) l I would like to add that I also follow this general approach consisting in defining such trivial functions where I need them. Being trivial does not mean that they are going to be used everywhere. It makes the code easier to *read*. My 2 cents. Martin