From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 55E69BBAF for ; Tue, 1 Aug 2006 23:15:33 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k71LFWos012795 for ; Tue, 1 Aug 2006 23:15:32 +0200 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 XAA01575 for ; Tue, 1 Aug 2006 23:15:32 +0200 (MET DST) Received: from fmmailgate01.web.de (fmmailgate01.web.de [217.72.192.221]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k71LFVwJ006302 for ; Tue, 1 Aug 2006 23:15:32 +0200 Received: from smtp08.web.de (fmsmtp08.dlan.cinetic.de [172.20.5.216]) by fmmailgate01.web.de (Postfix) with ESMTP id CE11ECB1A86 for ; Tue, 1 Aug 2006 23:15:27 +0200 (CEST) Received: from [84.165.136.117] (helo=wiko) by smtp08.web.de with smtp (WEB.DE 4.107 #114) id 1G81aJ-0003MZ-00 for caml-list@inria.fr; Tue, 01 Aug 2006 23:15:27 +0200 Message-ID: <004801c6b5b0$47811030$15b2a8c0@wiko> From: "Andreas Rossberg" To: "O'Caml Mailing List" References: <875c7e070608011347y62d2dd21lc55390cd4ffd00a1@mail.gmail.com> Subject: Re: [Caml-list] Unexpected '_a problem Date: Tue, 1 Aug 2006 23:20:00 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1807 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Sender: AndreasRossberg@web.de X-Sender: AndreasRossberg@web.de X-Miltered: at nez-perce with ID 44CFC474.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 44CFC473.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; rossberg:01 foo:01 foo:01 val:01 val:01 compiler:01 subtyping:01 syntax:01 wrote:01 polymorphic:01 polymorphic:01 caml-list:01 andreas:01 andreas:01 monomorphic:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=FORGED_RCVD_HELO autolearn=disabled version=3.0.3 "Chris King" wrote: > > # let create_foo () = object method foo (_: 'a) = () end;; > val create_foo : unit -> < foo : 'a -> unit > = > # let a = create_foo ();; > val a : < bar : '_a -> unit > = > > the compiler determines a is monomorphic, since 'a is in a > contravariant position. But why, when 'a is placed in a covariant > position: This has nothing to do with contravariance, nor with subtyping or objects at all. What you observe is the infamous "value restriction": roughly, a definition can only be polymorphic when its right-hand side is syntactically a value (i.e. a function, tuple, constant, etc or combination thereof). In your case it's an application. Also note that in the above code, it is the object that would be polymorphic, not the method! If you want a polymorphic method, the proper syntax is the following: # let create_foo () = object method foo : 'a.'a -> unit = fun _ -> () end;; val create_foo : unit -> < foo : 'a. 'a -> unit > = # let a = create_foo ();; val a : < foo : 'a. 'a -> unit > = # a#foo 5; a#foo true;; - : unit = () Here, `a' is a monomorphic object with a polymorphic method. - Andreas