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=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 2B515BBCA for ; Tue, 18 Mar 2008 11:56:48 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAGM830fAXQIn/2dsb2JhbACpOA X-IronPort-AV: E=Sophos;i="4.25,517,1199660400"; d="scan'208";a="10396605" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 18 Mar 2008 11:56:47 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m2IAul4b004548 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 18 Mar 2008 11:56:47 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqgBAOg830dQRFuwgGdsb2JhbACRAAEBCQqYLA X-IronPort-AV: E=Sophos;i="4.25,517,1199660400"; d="scan'208";a="23902379" Received: from furbychan.cocan.org ([80.68.91.176]) by mail4-smtp-sop.national.inria.fr with ESMTP; 18 Mar 2008 11:56:47 +0100 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1JbZUq-0006qc-6t for caml-list@inria.fr; Tue, 18 Mar 2008 10:56:44 +0000 Date: Tue, 18 Mar 2008 10:56:44 +0000 To: caml-list@inria.fr Subject: Re: [Caml-list] Yet another question about insufficient polymorphism Message-ID: <20080318105643.GA26219@annexia.org> References: <20080312193431.GA10622@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080312193431.GA10622@annexia.org> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Miltered: at concorde with ID 47DF9FEF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; polymorphism:01 mli:01 val:01 val:01 mutable:01 bool:01 mutable:01 bool:01 casts:01 textbox:98 textbox:98 wrote:01 caml-list:01 unit:03 unit:03 On Wed, Mar 12, 2008 at 07:34:32PM +0000, Richard Jones wrote: > I have a signature like this: > > newt.mli: > > type 'a component > > val form_add_component : > [> `Form ] component -> [> `Component ] component -> unit > val form_add_components : > [> `Form ] component -> [> `Component ] component list -> unit > > An implementation like this: > > newt.ml: > > type 'a component = { > co : newtComponent; > mutable in_form : bool; > } [...] > 04_form.ml: > > let text = textbox 1 1 15 5 [WRAP; SCROLL] in > textbox_set_text text "This is some text in a reflowed text box."; > let b1 = button 5 8 " OK " in > let b2 = button 5 13 "Cancel" in > let form = form None None [] in > form_add_components form [text; b1; b2]; > ^^ The answer to this, pointed out to me by milanst, is to write the type like this: type _component = { co : newtComponent; mutable in_form : bool; } type 'a component = _component which works as expected, without any "casts" needed on the call to form_add_components. Rich. -- Richard Jones Red Hat