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 XAA31023; Sun, 14 Dec 2003 23:06:18 +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 XAA30991 for ; Sun, 14 Dec 2003 23:06:17 +0100 (MET) Received: from kraid.nerim.net (smtp-100-sunday.nerim.net [62.4.16.100]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBEM6G120669 for ; Sun, 14 Dec 2003 23:06:16 +0100 (MET) Received: from karryall.dnsalias.org (karryall.dnsalias.org [62.4.18.180]) by kraid.nerim.net (Postfix) with ESMTP id B8F8241965; Sun, 14 Dec 2003 23:06:14 +0100 (CET) Received: by karryall.dnsalias.org (Postfix, from userid 500) id 77D331A0022; Sun, 14 Dec 2003 23:06:15 +0100 (CET) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16348.57047.312865.81137@karryall.dnsalias.org> Date: Sun, 14 Dec 2003 23:06:15 +0100 From: Olivier Andrieu To: Benjamin Geer Cc: Subject: Re: [Caml-list] polymorphic function not recognised as such In-Reply-To: <3FDCD850.9090005@socialtools.net> References: <3FDCB684.5000203@socialtools.net> <3FDCC2A8.2090901@ens-lyon.org> <3FDCD850.9090005@socialtools.net> X-Mailer: VM 7.17 under Emacs 21.3.1 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; andrieu:01 andrieu:01 caml-list:01 checker:01 char:01 char:01 checker:01 inferred:01 monomorphic:01 inference:01 bool:01 bool:01 int:01 int:01 polymorphic:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Benjamin Geer [Sunday 14 December 2003] : > > 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...) You could use a record holding a field with a fully polymorphic type : type t = { c : 'a. 'a -> 'a -> bool } let compare_things t1 t2 comparison_fun = match (t1, t2) with (Int i, _) -> comparison_fun.c i (int_of_thing t2) | (String s, _) -> comparison_fun.c s (string_of_thing t2) ;; -- Olivier ------------------- 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