From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id NAA28289; Mon, 15 Dec 2003 13:11:02 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 NAA28004 for ; Mon, 15 Dec 2003 13:11:00 +0100 (MET) Received: from nemerle.org (lilith.ii.uni.wroc.pl [156.17.4.7]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBFCB0X08551 for ; Mon, 15 Dec 2003 13:11:00 +0100 (MET) Received: from malekith by nemerle.org with local (Exim 4.24) id 1AVrYw-0006MK-Vm; Mon, 15 Dec 2003 13:10:59 +0100 Date: Mon, 15 Dec 2003 13:07:41 +0100 From: Michal Moskal To: Benjamin Geer Cc: "caml-list@inria.fr" Subject: Re: [Caml-list] polymorphic function not recognised as such Message-ID: <20031215120741.GA11364@roke.freak> Mail-Followup-To: Benjamin Geer , "caml-list@inria.fr" References: <3FDCB684.5000203@socialtools.net> <3FDCC2A8.2090901@ens-lyon.org> <3FDCD850.9090005@socialtools.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3FDCD850.9090005@socialtools.net> User-Agent: Mutt/1.4.1i X-PGP-Fingerprint: CF89 1B14 11BE 1CC9 2CA3 7497 5E32 69B4 BC71 B4C2 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; michal:01 moskal:01 malekith:01 pld-linux:01 caml-list:01 checker:01 char:01 char:01 checker:01 inferred:01 monomorphic:01 inference:01 quantified:01 foo:01 forall:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, Dec 14, 2003 at 09:38:24PM +0000, Benjamin Geer wrote: > Jean-Baptiste Rouquier wrote: > > compare_things : thing -> thing -> ('a -> 'a -> bool) -> bool > >doesn't mean that comparison_fun has to be polymorphic, but it means > >that any function with type ('a -> 'a -> bool), where 'a is any type, is > >acceptable. For instance, the type checker would accept a function of > >the type (char -> char -> bool). > > OK, but it seems that the type checker has inferred the type of > comparison_fun just by looking at its first use in compare_things, and > has decided that it must be monomorphic; this is an incorrect inference. > My naive impression is that if the type checker was willing to accept > both uses of comparison_fun as valid (or perhaps if it also looked at > the places where compare_things is called), it would conclude that > comparison_fun does indeed have to be polymorphic. In that case, I > would get a compile error if I tried to pass a non-polymorphic function > to compare_things. Would this be this asking too much? (I suspect the > answer is yes; I'm just curious...) Polymorphism in ML is flat, that is all type variables are quantified before the function, not in the arguments. The type ('a -> foo) -> bar means forall 'a. ('a -> foo) -> bar, and not (forall 'a. 'a -> foo) -> bar. This is one of the costs of type inference. In OCaml you can simulate deep polymorphism with polymorphic records (but you have to write explicit type then). -- : Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv : When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners