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 OAA11086; Wed, 11 Aug 2004 14:18:08 +0200 (MET DST) 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 OAA11836 for ; Wed, 11 Aug 2004 14:18:07 +0200 (MET DST) Received: from eris.rz.uni-saarland.de (eris.rz.uni-saarland.de [134.96.7.8]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i7BCI6mL014413 for ; Wed, 11 Aug 2004 14:18:06 +0200 Received: from cs.uni-sb.de (cs.uni-sb.de [134.96.254.254]) by eris.rz.uni-saarland.de (SGI-8.12.5/8.12.10) with ESMTP id i7BCI5CS11621046 for ; Wed, 11 Aug 2004 14:18:05 +0200 (CST) Received: from mail.cs.uni-sb.de (mail.cs.uni-sb.de [134.96.254.200]) by cs.uni-sb.de (8.13.1/2004080400) with ESMTP id i7BCI0wj029805 for ; Wed, 11 Aug 2004 14:18:04 +0200 (CEST) Received: from ps.uni-sb.de (grizzly.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.13.1/2004080200) with ESMTP id i7BCHvB4005679 for ; Wed, 11 Aug 2004 14:17:59 +0200 (CEST) X-Authentication-Warning: email: Host grizzly.ps.uni-sb.de [134.96.186.68] claimed to be ps.uni-sb.de Received: from ps.uni-sb.de (groove.ps.uni-sb.de [134.96.186.172]) by ps.uni-sb.de (8.12.10/8.12.10) with ESMTP id i7BCHt9x018868; Wed, 11 Aug 2004 14:17:55 +0200 Message-ID: <411A0E73.4060708@ps.uni-sb.de> Date: Wed, 11 Aug 2004 14:17:55 +0200 From: Andreas Rossberg User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114 X-Accept-Language: en-us, en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] strange effect of type annotation References: <16665.61343.130286.600455@gargle.gargle.HOWL> In-Reply-To: <16665.61343.130286.600455@gargle.gargle.HOWL> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.5.1 (eris.rz.uni-saarland.de [134.96.7.8]); Wed, 11 Aug 2004 14:18:05 +0200 (CEST) X-AntiVirus: checked by AntiVir Milter 1.0.6; AVE 6.27.0.4; VDF 6.27.0.6 X-Miltered: at nez-perce with ID 411A0E7E.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; rossberg:01 rossberg:01 uni-sb:01 caml-list:01 0.,:01 0.,:01 checker:01 ocaml's:01 annotations:01 monomorphic:01 placeholder:01 quantified:01 checker:01 type-check:01 uni-sb:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk fis@wiwi.hu-berlin.de wrote: > >> let good : (int * float) = let x = fst in (x (0,1), x (0., 1.));; >> let bad : (int * float) = let x: ('a * 'a) -> 'a = fst in (x (0,1), x (0., 1.));; > > The type checker sais: > >> let bad : (int * float) = let x: ('a * 'a) -> 'a = fst in (x (0,1), x (0., 1.));; >> ^^^^^^^^ >>This expression has type float * float but is here used with type int * int This is due to OCaml's counter-intuitive interpretetion of type variables in type annotations. The 'a is not polymorphic! Rather, it is considered a monomorphic placeholder for some concrete type (IOW it is not quantified). The effect is similar to saying let x: (_ * _) -> _ = fst in (x (0,1), x (0., 1.)) except that you put the additional constraint that all occurances of the wildcard have to denote the same type. When the type checker sees the first application of x it then knows that that 'a has to denote int. So it behaves as if you had written let x: (int * int) -> int = fst in (x (0,1), x (0., 1.)) (Personally, I never understood the rationale for that treatment of type variables. It is one of the things I find more reasonable in SML, where the equivalent of your example would type-check.) Cheers, - Andreas -- Andreas Rossberg, rossberg@ps.uni-sb.de Let's get rid of those possible thingies! -- TB ------------------- 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