Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Some/None
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-04-24 (18:30)
From: Michal Moskal <malekith@p...>
Subject: Re: [Caml-list] Some/None
On Wed, Apr 24, 2002 at 02:48:41PM +0200, Oliver Bandel wrote:
> How are Some/None defined, what are they good for?

This is similar in idea to NULL pointer in C. E.g. struct foo *ptr
is NULL iff ptr cannot be assigned any reasonable value of type foo.
You can use 'foo option' in ML the same way -- x : foo option is
None if no foo is the right value for x.

> A small, simple example will help a lot.

let head x =
  match x with
  | h::_ -> Some h
  | [] -> None

Here if no reasoable value of the head of the list can be returned
'None' is used.

I personally use mutable fields in records of option type. They are
initially None, and are filled at some step of computations. However
this is non-functional/ugly/etc ;)

: Michal Moskal :::::::: malekith/at/ :  GCS {C,UL}++++$ a? !tv
: PLD Linux ::::::: Wroclaw University, CS Dept :  {E-,w}-- {b++,e}>+++ h
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: