From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.6 required=5.0 tests=RCVD_IN_SORBS_WEB,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 44D2CBC37 for ; Wed, 29 Jul 2009 01:05:01 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArIBAL8gb0rRVdramGdsb2JhbACCIIx8iiw/AQEBAQEICQwHE6p2kCQBBYQQ X-IronPort-AV: E=Sophos;i="4.43,285,1246831200"; d="scan'208";a="31818827" Received: from mail-bw0-f218.google.com ([209.85.218.218]) by mail3-smtp-sop.national.inria.fr with ESMTP; 29 Jul 2009 01:05:00 +0200 Received: by bwz18 with SMTP id 18so379284bwz.27 for ; Tue, 28 Jul 2009 16:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:references:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:x-mailer :mime-version:subject:date:cc; bh=rh4s3XuDazG+vhOU3D0jZ/Pc6VCnEEop9QhgT6SFSkY=; b=oo01SmajJbyeuJL5AIkzYfIi+WuQk0EoPl7qL5hMm+ZmK2noxmnnc5fBpOT0RFJrMS gKvNGAsMiO/JdAZ3PQI3K+10G3dxExPRq3I7vIFGdho/xBhluBaC3iKIw5vcR9JA91x3 DLsVN7k6vdkMGQLs0s5ExlyFOQpzgQ0JWX8qk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=references:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:x-mailer:mime-version:subject:date:cc; b=rtbzYynwMo/9Xkzd3iZJSqzdRY2jb0ESQNc3JrBp2BNaJZ1PVSONYuVEB2ny8ZanSz 5C9AbczE8ixF54xMFd9MDjcrpf6yHcmYJ1SffGyGBqA8GtCZsbqly7fIkD2oj5GmYi17 XS3StcQm98w/hDWDI+kgi9EyZ1Dh6rIc6joX8= Received: by 10.204.112.205 with SMTP id x13mr4884009bkp.170.1248822300104; Tue, 28 Jul 2009 16:05:00 -0700 (PDT) Received: from ?10.0.199.201? ([193.253.141.89]) by mx.google.com with ESMTPS id 13sm935612fks.52.2009.07.28.16.04.56 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 28 Jul 2009 16:04:59 -0700 (PDT) References: <200907290028.29488.jon@ffconsultancy.com> Message-Id: From: Philippe To: Jon Harrop In-Reply-To: <200907290028.29488.jon@ffconsultancy.com> Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: quoted-printable X-Mailer: iPhone Mail (5G77) Mime-Version: 1.0 (iPhone Mail 5G77) Subject: Re: [Caml-list] annotations and type-checking Date: Wed, 29 Jul 2009 01:04:45 +0200 Cc: "caml-list@yquem.inria.fr" X-Spam: no; 0.00; annotations:01 bool:01 bool:01 unify:01 quantifiers:01 quantified:01 beginner's:01 ocaml:01 bug:01 28,:98 2009:98 harmless:98 frog:98 beginners:01 wrote:01 Le 29 juil. 09 =C3=A0 01:28, Jon Harrop a =C3=A9cr= it : > On Tuesday 28 July 2009 22:47:25 Aaron Bohannon wrote: >> let f (x : 'a) : 'a =3D x in (f true, f 3);; > > Err, good question. :-) > > # let f : _ =3D fun x -> x in f true, f 3;; > - : bool * int =3D (true, 3) The type of f here is something like 'a. 'a -> 'a. So you can use it =20 on bool or int. I understand it like [], like in the expression (3 :: =20= [], true :: []) where it has type 'a. 'a list (unfortunately it is not =20= synctacally correct to say let f : 'a. 'a -> 'a =3D fun x -> x, I don't know why.) > > # let f : 'a =3D fun x -> x in f true, f 3;; > Error: This expression has type int but is here used with type bool Here you specify that there exists a type named 'a, which is the =20 return type of f and which should unify with both bool and int. Hence =20= the typing error. > > > I'm guessing the scope of the 'a is not what you'd expect but I have =20= > no idea > why. I'd have thought the latter would be a harmless type =20 > annotation... My guess is that the problem here is not about scope but about =20 quantifiers : the type of f is quantified universally by default but =20 the annotation constrains the type of f to a fixed (yet unknown) type =20= in the subsequent expression (in that sense, yes, the scope of f plays =20= a crucial role). HTH, Ph. > > > Any takers? > > --=20 > Dr Jon Harrop, Flying Frog Consultancy Ltd. > http://www.ffconsultancy.com/?e > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs