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: -- (:)
From: Markus Mottl <markus@o...>
Subject: Re: [Caml-list] Some/None
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.

When you want to "see" what an optional value looks like, you use

  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.

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


Markus Mottl                                   
Austrian Research Institute
for Artificial Intelligence        
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: