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 RAA24041; Wed, 24 Apr 2002 17:15:09 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA24232 for ; Wed, 24 Apr 2002 17:15:04 +0200 (MET DST) Received: from hirsch.in-berlin.de (hirsch.in-berlin.de [192.109.42.6]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3OFF4122759 for ; Wed, 24 Apr 2002 17:15:04 +0200 (MET DST) Received: from hirsch.in-berlin.de (localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with ESMTP id g3OFF3TL032258 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT); Wed, 24 Apr 2002 17:15:03 +0200 Received: (from uucp@localhost) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with UUCP id g3OFF2iu032255; Wed, 24 Apr 2002 17:15:02 +0200 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: caml-list@inria.fr Received: from localhost (oliver@localhost) by first.in-berlin.de (8.7.6/8.7.3) with SMTP id QAA01519; Wed, 24 Apr 2002 16:23:34 +0200 Date: Wed, 24 Apr 2002 16:23:34 +0200 (MET DST) From: Oliver Bandel To: Michal Moskal cc: caml-list@inria.fr Subject: Re: [Caml-list] Some/None In-Reply-To: <20020424133110.GA10571@ep09.kernel.pl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, On Wed, 24 Apr 2002, Michal Moskal wrote: > 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. OK, In had typed it into the toplevel and as expected, it does not give back a pure type (like int's or strings). It gives back None or Some 8 or Some "hello" If aplicated to an empty list, a list of integers or a list of strings. Is this really a commeon way of programming? If I work on a list of integers or a list of strings, does it really have advantages to use such a type? > > I personally use mutable fields in records of option type. They are > initially None, and are filled at some step of computations. Hmhh, ok. I now see the similarity to NULL in C. > However > this is non-functional/ugly/etc ;) Pattern match itself is not functional. How can such things be expressed in a functional way? (Maybe I have to try it in Haskell, it's constraints to be functional are much stronger; when using Ocaml it seems to be that very often the imperative style creeps in - even unconsciously). Ciao, Oliver ------------------- 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