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 RAA25105; Wed, 24 Apr 2002 17:43:56 +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 RAA25076 for ; Wed, 24 Apr 2002 17:43:55 +0200 (MET DST) Received: from mailhost.trusted-logic.fr (mailhost.trusted-logic.fr [194.250.150.5]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g3OFhs124003 for ; Wed, 24 Apr 2002 17:43:54 +0200 (MET DST) Received: from ouessant.trusted-logic.fr (ouessant.trusted-logic.fr [192.168.1.201]) by mailhost.trusted-logic.fr (Postfix) with ESMTP id 65B6DF808F for ; Wed, 24 Apr 2002 17:43:53 +0200 (CEST) Received: (from lacas@localhost) by ouessant.trusted-logic.fr (8.9.3/8.9.3) id RAA03178 for caml-list@inria.fr; Wed, 24 Apr 2002 17:43:53 +0200 Date: Wed, 24 Apr 2002 17:43:53 +0200 From: Samuel Lacas To: caml-list@inria.fr Subject: Re: [Caml-list] Some/None Message-ID: <20020424174353.A29676@ouessant.trusted-logic.fr> References: <20020424133110.GA10571@ep09.kernel.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 1.0pre3us In-Reply-To: X-Send-From: ouessant.trusted-logic.fr X-Operating-System: Linux ouessant.trusted-logic.fr 2.2.19 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Oliver Bandel a écrit 1.8K le Wed, Apr 24, 2002 at 04:23:34PM +0200: # # 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" Naturally. The type ('int option) is not the same as the type "int", because you have the "None" value. # Is this really a common way of programming? I suppose so. # If I work on a list of integers or a list of # strings, does it really have advantages to # use such a type? Yes: it allows you to manage an error case for a function supposed to return a value of type a, but which may sometimes return nothing. It's lighter than exceptions (I think) and much more safe than having a "null" pointer-style ugly coding (or other twisted way such as saying "return -1" if not found). # Pattern match itself is not functional. Don't know, but without much thinking, no imperative language having a similar mechanism built-in comes to my mind. Don't trust me, though :) # 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). Haskell preludes contains: -- Maybe type data Maybe a = Nothing | Just a deriving (Eq, Ord, Read, Show) which serves exactly the same. Replace Maybe by option, Nothing by None, and Just by Some. No "unconscious" imperative creeping here :) sL ------------------- 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