From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA21227; Wed, 24 Apr 2002 15:41:27 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA20003 for ; Wed, 24 Apr 2002 15:41:26 +0200 (MET DST) Received: from kiefer.ai.univie.ac.at (kiefer.ai.univie.ac.at [131.130.174.157]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3ODfOP14795 for ; Wed, 24 Apr 2002 15:41:24 +0200 (MET DST) Received: (from markus@localhost) by kiefer.ai.univie.ac.at (8.9.3/8.9.3/Debian 8.9.3-21) id PAA29109; Wed, 24 Apr 2002 15:41:16 +0200 Date: Wed, 24 Apr 2002 15:41:16 +0200 From: Markus Mottl To: Oliver Bandel Cc: caml-list@inria.fr Subject: Re: [Caml-list] Some/None Message-ID: <20020424134116.GB27574@kiefer.ai.univie.ac.at> Mail-Followup-To: Oliver Bandel , caml-list@inria.fr References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.3.26i Organization: Austrian Research Institute for Artificial Intelligence Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 pattern-matching: 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. LG, Markus -- Markus Mottl markus@oefai.at Austrian Research Institute for Artificial Intelligence http://www.oefai.at/~markus ------------------- 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