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 UAA25026; Sun, 14 Dec 2003 20:14:17 +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 UAA25171 for ; Sun, 14 Dec 2003 20:14:14 +0100 (MET) Received: from rabelais.socialtools.net (rabelais.socialtools.net [81.2.94.243]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id hBEJED101869 for ; Sun, 14 Dec 2003 20:14:14 +0100 (MET) Received: by rabelais.socialtools.net (Postfix, from userid 108) id 909CE2332A; Sun, 14 Dec 2003 19:14:13 +0000 (GMT) Received: from socialtools.net (chaucer.socialtools.net [81.2.94.242]) by rabelais.socialtools.net (Postfix) with ESMTP id AD702232DA for ; Sun, 14 Dec 2003 19:14:12 +0000 (GMT) Message-ID: <3FDCB684.5000203@socialtools.net> Date: Sun, 14 Dec 2003 19:14:12 +0000 From: Benjamin Geer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-gb, en, fr, it MIME-Version: 1.0 To: caml-list@inria.fr Subject: [Caml-list] polymorphic function not recognised as such Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 2.61 (1.212.2.1-2003-12-09-exp) on rabelais.socialtools.net X-Spam-Status: No, hits=-4.9 required=5.0 tests=BAYES_00 autolearn=ham version=2.61 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; compiler:01 bool:01 bool:01 int:01 int:01 polymorphic:01 polymorphic:01 match:02 match:02 compile:02 comparison:02 comparison:02 string:03 string:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Can anyone explain to me why the following doesn't compile: ---------- type thing = Int of int | String of string ;; let int_of_thing t = match t with Int i -> i | String s -> int_of_string s ;; let string_of_thing t = match t with Int i -> string_of_int i | String s -> s ;; let compare_things t1 t2 comparison_fun = match (t1, t2) with (Int i, _) -> comparison_fun i (int_of_thing t2) | (String s, _) -> comparison_fun s (string_of_thing t2) ;; let is_less_than t1 t2 = compare_things t1 t2 (<) ;; let is_greater_than t1 t2 = compare_things t1 t2 (>) ;; ---------- The compiler says: File "test.ml", line 16, characters 38-39: This expression has type string but is here used with type int It seems to have decided that in the function compare_things, comparison_fun is int -> int -> 'a because that's how it's used in the first pattern, not realising that I mean to pass a polymorphic function, 'a -> 'a -> bool. Is there a way to make this work? (Specifying the type of comparison_fun as 'a -> 'a -> bool makes no difference.) Ben ------------------- 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