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 HAA28109; Tue, 23 Dec 2003 07:33:06 +0100 (MET) 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 HAA28215 for ; Tue, 23 Dec 2003 07:31:44 +0100 (MET) Received: from mail.eecs.harvard.edu (bowser.eecs.harvard.edu [140.247.60.24]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBN6Vhv17387 for ; Tue, 23 Dec 2003 07:31:43 +0100 (MET) Received: by mail.eecs.harvard.edu (Postfix, from userid 32210) id 46ECF54C4D5; Tue, 23 Dec 2003 01:31:42 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.eecs.harvard.edu (Postfix) with ESMTP id 4433354C4B3; Tue, 23 Dec 2003 01:31:42 -0500 (EST) Date: Tue, 23 Dec 2003 01:31:42 -0500 (EST) From: Michael Jeffrey Tucker To: Tyler Eaves Cc: Matt Gushee , caml-list@inria.fr Subject: Re: [Caml-list] Frustrated Beginner In-Reply-To: Message-ID: <20031223012223.W47896@bowser.eecs.harvard.edu> 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 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; tucker:01 mtucker:01 caml-list:01 foo:01 endline:01 endline:01 foo:01 struct:01 enum:01 val:01 val:01 unspecified:01 enforced:01 argh:01 argh:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi Tyler, > > 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? You're pretty close - in this case, you can think of foo as being a structure that contains a tag and potentially a valid value. In C this might be represented by: struct foo_type { enum {Some, None} opt; value_t val; }; If the opt field of the structure is set to Some, then you are free to look at the val field. If it's none, then the value in the val field is unspecified and should be ignored (of course this is more stringently enforced in OCaml). In OCaml an "option type" variable has either the value "Some xxx" or "None" where xxx is a value. So, a "string option" variable might have the value Some "hi", Some "qwery" or None. If you pattern match on a variable of this type, as in: match foo with | None -> "Argh! No value." | Some x -> x Then, you are creating a new binding for x, where x will be assigned the value portion. So, in the example values above, this code will evaluate to (in order): "hi" "qwery" "Argh! No value." Hope that helps, Mike ------------------- 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