English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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/pld.org.pl :  GCS {C,UL}++++$ a? !tv
: PLD Linux ::::::: Wroclaw University, CS Dept :  {E-,w}-- {b++,e}>+++ h
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners