From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.2 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id AD89BBC0B for ; Wed, 17 Jan 2007 01:30:37 +0100 (CET) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.238]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l0H0Ua7G025871 for ; Wed, 17 Jan 2007 01:30:37 +0100 Received: by wr-out-0506.google.com with SMTP id 67so1761655wri for ; Tue, 16 Jan 2007 16:30:35 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=OTZVPbeQ83QC+RYzmPfbd21RXn448fhOmJyXupRLyuGtPg43AFKVRsNZXn9YhXi5hkJGfTkNDRsju38P1NoAvZPG7jvaqJLq9zDN+HJxidAuqzzajKHQyw2fN7VlgFbqwxqmPKcNzD2Xo7rmhpiD47fvXFl55vCoI8srLJO9cGQ= Received: by 10.78.18.3 with SMTP id 3mr1225965hur.1168993834690; Tue, 16 Jan 2007 16:30:34 -0800 (PST) Received: by 10.78.159.17 with HTTP; Tue, 16 Jan 2007 16:30:34 -0800 (PST) Message-ID: Date: Wed, 17 Jan 2007 13:30:34 +1300 From: "Jonathan Roewen" To: Tom Subject: Re: [Caml-list] Polymorphic Variants Cc: caml-list In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-j-chkmail-Score: MSGID : 45AD6E2C.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 45AD6E2C.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; variants:01 variants:01 compiler:01 enforces:01 ocaml:01 struct:01 struct:01 beginner's:01 ocaml:01 bug:01 polymorphic:01 polymorphic:01 beginners:01 wrote:01 workaround:01 There are interesting, and extremely useful use cases for polymorphic variants. One very cool example (IMO) is an xhtml module which mixes phantom types with polymorphic variants so that the compiler enforces creation of valid xhtml documents (with some limitations...). Also, OCaml has ways to control whether a polymorphic variant argument to a function is open/extensible or not. As for the records issue: you can wrap them in sub modules to workaround the name clash problem by fully qualifying the fields with their module name. E.g. module A = struct type t = { x : int; y : int } end module B = struct type t = { x : float; y : float } end open A;; open B;; let a = { A.x = 2; A.y = 3 };; let b = { B.x = 1.; B.y = 2. };; let x_from_A v = v.A.x;; let x_from_B v = v.B.x;; Jonathan On 1/17/07, Tom wrote: > I have a question... I hope it will not be dismissed right away, thou I > guess most of you will find it stupid (some might however agree with me... > hopefully). > > Cut the crap! > > So... why actually are polymorphic variants useful? Why can't they simply be > implemented as normal, concrete (or how would you call them? ...) variants? > Doesn't the use of polymorphic variants just mess up the function type? > > I'm not orthogonally against polymorphic variants, it's just that I am > looking for an alternative concept that could be used instead... Maybe > subtyped records? > > - Tom > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: > http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > >