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 BE53DBBC1 for ; Wed, 12 Mar 2008 20:34:34 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmMBAAbN10fAXQImh2dsb2JhbACQcgEBAQgKKZcG X-IronPort-AV: E=Sophos;i="4.25,490,1199660400"; d="scan'208";a="10193673" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 12 Mar 2008 20:34:34 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m2CJYXqW016985 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 12 Mar 2008 20:34:34 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmMBAMrM10dQRFuwh2dsb2JhbACQcgEBAQgKKZcO X-IronPort-AV: E=Sophos;i="4.25,490,1199660400"; d="scan'208";a="23690910" Received: from furbychan.cocan.org ([80.68.91.176]) by mail4-smtp-sop.national.inria.fr with ESMTP; 12 Mar 2008 20:34:33 +0100 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1JZWie-00031X-GH for caml-list@inria.fr; Wed, 12 Mar 2008 19:34:32 +0000 Date: Wed, 12 Mar 2008 19:34:32 +0000 To: caml-list@inria.fr Subject: Yet another question about insufficient polymorphism Message-ID: <20080312193431.GA10622@annexia.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Miltered: at discorde with ID 47D83049.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; polymorphism:01 polymorphism:01 mli:01 val:01 val:01 mutable:01 bool:01 failwith:01 iter:01 cmo:01 mli:01 textbox:98 textbox:98 functions:01 variant:02 This is yet another "insufficient polymorphism" question that I just can't work out ... 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; } let form_add_component form co = if co.in_form then failwith "component can only be added to a single form"; newtFormAddComponent form.co co.co; co.in_form <- true let form_add_components form components = List.iter (fun co -> form_add_component form co) components And my test program is: 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]; ^^ File "examples/04_form.ml", line 17, characters 33-35: This expression has type [ `Button | `Component ] Newt.component but is here used with type [ `Component | `Textbox ] Newt.component The second variant type does not allow tag(s) `Button make: *** [examples/04_form.cmo] Error 2 This all worked until I added the newt.mli file. (I previously just had a newt.ml file, with explicit types on all the functions). Rich. -- Richard Jones Red Hat