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 (16:20)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Some/None

On Wed, 24 Apr 2002, Markus Mottl wrote:

> Oliver Bandel schrieb am Mittwoch, den 24. April 2002:
> > I have not found any description in the
> > Ref-Manual (for 3.01).
> This type is implicitly defined in the "Pervasives"-module as follows:
>   type 'a option = None | Some of 'a
> As the name indicates, you can use it to describe optional values, i.e.
> you either have "Some value" or you have "None". It has a similar purpose
> as NULL-pointers in C, but with the difference that it is perfectly safe
> to handle.

OK, I see the advantage here: No coredump-problems like in C.

>   match maybe_data with
>   | Some data ->  (* do something with "data" *)
>   | None ->       (* handle case when no data available *)
> There is no way to accidently access "maybe_data" as if it were "Some
> data" even though it is actually "None" - a very common programming
> mistake in C.

OK, looks like the problem with Unix.ENOENT.

> The option type is really just an ordinary algebraic datatype, which is
> useful enough to deserve being defined in the standard library.



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