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 HAA26220; Tue, 23 Dec 2003 07:38:09 +0100 (MET) 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 HAA28709 for ; Tue, 23 Dec 2003 07:38:08 +0100 (MET) Received: from speakeasy.org (dialup-67.75.211.180.Dial1.Seattle.Level3.net [67.75.211.180]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBN6c6b28506 for ; Tue, 23 Dec 2003 07:38:06 +0100 (MET) Received: (from shawnw@localhost) by speakeasy.org (8.10.1/8.10.1) id hBN6WlF00849 for caml-list@inria.fr; Mon, 22 Dec 2003 22:32:47 -0800 Date: Mon, 22 Dec 2003 22:32:47 -0800 From: Shawn Wagner To: caml-list@inria.fr Subject: Re: [Caml-list] Frustrated Beginner Message-ID: <20031223063247.GA602@speakeasy.org> Mail-Followup-To: caml-list@inria.fr References: <1072152186.59938.30.camel@tylere> <29911.24.6.3.124.1072153159.squirrel@www.cs.fiu.edu> <1072152186.59938.30.camel@tylere> <20031223053451.GB1145@swordfish> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; shawnw:01 caml-list:01 gushee:01 foo:01 endline:01 endline:01 foo:01 hash:01 shawnw:01 speakeasy:01 speakeasy:01 null:01 null:01 syntax:02 match:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, Dec 23, 2003 at 01:11:08AM -0500, Tyler Eaves wrote: > > On Dec 23, 2003, at 12:34 AM, Matt Gushee wrote: > > > > match foo with > > | None -> print_endline "Nothing"; "" > > | Some x -> print_endline x; x > > If I understand the match syntax correctly, in this case, x takes the > value of foo? Not quite. foo is an option type - it can hold either Some valid bit of data (A string in this case), or nothing (None). x ends up taking the value of whatever the valid bit of data is. The same thing in C would look like if (foo) { puts(foo); return foo; } else { puts("Nothing"); return ""; } Options are nicer, however, because you don't have the problem that crops up in C of not handling cases where NULL is a valid bit of data because it's treated as 'No data'. Hash lookup functions that return NULL when a key's not found are a classic example. What happens when you want to store NULL in one? -- Shawn Wagner shawnw@speakeasy.org ------------------- 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