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 NAA25766; Sat, 28 Feb 2004 13:44:20 +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 NAA25216 for ; Sat, 28 Feb 2004 13:44:19 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from tonto (CM-lcon6-153-5.cm.vtr.net [200.83.153.5]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i1SCiGae001553 for ; Sat, 28 Feb 2004 13:44:17 +0100 Received: from www-data by tonto with local (Exim 3.36 #1 (Debian)) id 1Ax3pI-0004is-00 for ; Sat, 28 Feb 2004 09:44:16 -0300 Received: from 139.229.3.218 (SquirrelMail authenticated user andrew) by localhost with HTTP; Sat, 28 Feb 2004 09:44:16 -0300 (CLST) Message-ID: <56138.139.229.3.218.1077972256.squirrel@localhost> Date: Sat, 28 Feb 2004 09:44:16 -0300 (CLST) Subject: [Caml-list] Newbie: Aliases for polymorphic variants From: "andrew cooke" To: "ocaml list" Reply-To: andrew@acooke.org User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; newbie:01 foo:01 haskell:01 ad-hoc:01 gallery:99 ocaml:01 variants:01 variants:01 int:01 int:01 polymorphic:01 polymorphic:01 constructors:01 syntax:02 syntax:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I've just been looking at polymorphic variants. They seem quite neat. However, I have some questions.... 1 - It seems to me that they could be particularly useful for solving those nasty practical problems that occur way down the line with old systems where you want to combine previously separate features in some way. However, to do that, it seems like all code has to use polymorphic variants from the start. Is that right? That seems OK, except that they seem to make for a lot more typing. Is there a syntax for defining something like type aliases? I'm looking for something like: alias 'a Node = `Node int * 'a `Node * 'a `Node so that I can type just 'a Node instead of `Node int * 'a `Node * 'a `Node everywhere 2 - Alternatively, say I have type 'a beginWithF = [Foo of 'a | Flob of int * 'a] type 'a beginWithG = [Goo of 'a] is there a syntax something like: type 'a beginWithFOrG = ['a beginWithF | 'a beginWithG] or do I have to explicitly list all the separate constructors? 3 - Am I right in thinking that fucntions cannot be defined with pattern matching to the left of "=" in OCaml? (ie not like Haskell) If this were possible then I think you'd have ad-hoc polymorphism for free because you could have: fun sum (`Integer i) (`Integer j) = `Integer (i + j) fun sum (`Real x) (`Real y) = `Real (x +. y) Does that make sense? 4 - Taking (3) further, couldn't you give all types an implicit polymorphic variant constructor? Then you could have types like [int | float] directly. Does that make sense? Thanks, Andrew -- __ _ __ ___ ___| |_____ work web site: http://www.ctio.noao.edu/~andrew / _` / _/ _ \/ _ \ / / -_) personal web site: http://www.acooke.org/andrew \__,_\__\___/\___/_\_\___| personal gallery: http://www.acooke.org/pancito ------------------- 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