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 662C7BB84 for ; Wed, 2 Aug 2006 00:09:14 +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 k71M9DIc019221 for ; Wed, 2 Aug 2006 00:09:14 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA01936 for ; Wed, 2 Aug 2006 00:09:13 +0200 (MET DST) Received: from wx-out-0102.google.com (wx-out-0102.google.com [66.249.82.193]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k71M9B6k019211 for ; Wed, 2 Aug 2006 00:09:12 +0200 Received: by wx-out-0102.google.com with SMTP id s7so653591wxc for ; Tue, 01 Aug 2006 15:09:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=UAs4cQcHt6Bt9sUZvpz36RhVcmEP7uKQn7CpnT65Fgo/XgJT9HDMBgu0dy0fyIjbdpya03R1e06SU8g230CbqbOkh1NZvRQl3skpuBi27O8VTxPZTUmKOR5mU8QmEDaDRVO14tDTvpoUCwzGV9lng79yVc9vUxbIcSeBdsnv/pw= Received: by 10.78.200.3 with SMTP id x3mr47339huf; Tue, 01 Aug 2006 15:09:11 -0700 (PDT) Received: by 10.78.166.20 with HTTP; Tue, 1 Aug 2006 15:09:10 -0700 (PDT) Message-ID: <6b8a91420608011509s696233cew8d499f315aa0cba9@mail.gmail.com> Date: Wed, 2 Aug 2006 00:09:11 +0200 From: "Remi Vanicat" To: "O'Caml Mailing List" Subject: Re: [Caml-list] Unexpected '_a problem Cc: "Chris King" In-Reply-To: <004801c6b5b0$47811030$15b2a8c0@wiko> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <875c7e070608011347y62d2dd21lc55390cd4ffd00a1@mail.gmail.com> <004801c6b5b0$47811030$15b2a8c0@wiko> X-j-chkmail-Score: MSGID : 44CFD108.000 on nez-perce : j-chkmail score : X : 0/20 1 X-Miltered: at nez-perce with ID 44CFD109.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44CFD108.000 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 compiler:01 polymorphism:01 2006:98 wrote:01 polymorphic:01 caml-list: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.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.3 2006/8/1, Andreas Rossberg : > "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. Nope : # let f () = [];; val f : unit -> 'a list = # let x = f ();; val x : 'a list = [] I have an application, but as it is covariant, the compiler lift the value restriction, and make it covariant. But for a reson I don't fully understood, one cannot do: # let f () (_ : 'a -> unit) = ();; val f : unit -> ('a -> unit) -> unit = # f ();; - : ('_a -> unit) -> unit = and have full polymorphism (when f() type is covariant). Note that this will work: # type +'a t = Foo of ((('a -> unit) -> unit));; type 'a t = Foo of (('a -> unit) -> unit) # let f () = Foo (fun _ -> ());; val f : unit -> 'a t = # f ();; - : 'a t = Foo (we have full polymorphisme here, with a code that is mostly equivalent to the first one, but not completely).