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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 5108FBC69 for ; Sun, 4 Mar 2007 22:03:10 +0100 (CET) Received: from out5.smtp.messagingengine.com (out5.smtp.messagingengine.com [66.111.4.29]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l24L3975013518 for ; Sun, 4 Mar 2007 22:03:10 +0100 Received: from out1.internal (unknown [10.202.2.149]) by out1.messagingengine.com (Postfix) with ESMTP id E7B481F5306; Sun, 4 Mar 2007 16:03:08 -0500 (EST) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by out1.internal (MEProxy); Sun, 04 Mar 2007 16:03:08 -0500 X-Sasl-enc: NoAQqiLD30biCiOvpo+CyQ4C4qVTZZ0t5Qfw/2daOvnj 1173042188 Received: from adsl-75-18-114-78.dsl.sndg02.sbcglobal.net (adsl-75-18-114-78.dsl.sndg02.sbcglobal.net [75.18.114.78]) by mail.messagingengine.com (Postfix) with ESMTP id 1999C20AC0; Sun, 4 Mar 2007 16:03:08 -0500 (EST) Date: Sun, 4 Mar 2007 13:02:57 -0800 (PST) From: Martin Jambon X-X-Sender: martin@droopy To: Lukasz Stafiniak Cc: Zheng Li , caml-list@inria.fr Subject: Re: [Caml-list] Re: records with polymorphic variants? In-Reply-To: <4a708d20703040824o20b1d572h786d46da586c9977@mail.gmail.com> Message-ID: References: <45EA613F.3030104@generation.net> <87k5xxjdgv.fsf@gmail.com> <4a708d20703040824o20b1d572h786d46da586c9977@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 45EB340D.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 variants:01 lukasz:01 polymorphism:01 beginner's:01 ocaml:01 bug:01 2007,:98 polymorphic:01 polymorphic:01 beginners:01 wrote:01 wrote:01 caml-list:01 caml-list:01 On Sun, 4 Mar 2007, Lukasz Stafiniak wrote: > On 3/4/07, Zheng Li wrote: >> >> Hi, >> >> Eliot Handelman writes: >> > type f = [ `A of int ] >> > >> > type r = { x : f } >> > >> > but then I can't do this: >> > >> > { x = `B "test" } >> Here you want type f polymorphic, however as the type of a record field, >> its >> polymorphism has to be reflected (bound) as type parameter in the >> declaration >> of r. > > Yes, but the type f itself is not polymorphic, it is not [> f]. You can do this directly if you prefer: type 'a f = 'a constraint 'a = [> `A of int ] >> I guess you want the follows >> >> # type 'a r = { x : 'a } constraint 'a = [> f] >> type 'a r = { x : 'a; } constraint 'a = [> f ] >> # {x = "test"} >> Characters 6-12: >> { x = "test"};; >> ^^^^^^ >> This expression has type string but is here used with type [> f ] >> # {x = `B "test"} >> - : [> `A of int | `B of string ] r = {x = `B "test"} >> > Nice! I didn't realize this is possible. Thanks. > > _______________________________________________ > 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 > -- Martin Jambon http://martin.jambon.free.fr