caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Johannes Kanig <johannes.kanig@gmail.com>
To: Philippe <philippe.veber@googlemail.com>
Cc: Jon Harrop <jon@ffconsultancy.com>,
	"caml-list@yquem.inria.fr" <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] annotations and type-checking
Date: Wed, 29 Jul 2009 07:38:24 +0200	[thread overview]
Message-ID: <4A6FE050.2040803@gmail.com> (raw)
In-Reply-To: <A364D077-4ABE-4CDC-A4D1-B56A5738F60A@googlemail.com>

Philippe wrote:
> Le 29 juil. 09 à 01:28, Jon Harrop <jon@ffconsultancy.com> a écrit :
>> I'm guessing the scope of the 'a is not what you'd expect but I have 
>> no idea
>> why. I'd have thought the latter would be a harmless type annotation...
> 
> My guess is that the problem here is not about scope but about 
> quantifiers : the type of f is quantified universally by default but the 
> annotation constrains the type of f to a fixed (yet unknown) type in the 
> subsequent expression (in that sense, yes, the scope of f plays a 
> crucial role).

I think John Harrop is right and the scope of 'a is really the issue 
here. First of all, transforming "let ... in" into a top-level let makes 
the code work again:

# let f (x : 'a) : 'a = x;;
val f : 'a -> 'a = <fun>
# f true;;
- : bool = true
# f 3;;
- : int = 3

which suggests that the scope of type variables in annotations is a 
top-level let-binding. I think I have read about this somewhere, but I 
can't find the right page of the manual ...

Also, the following code fails:

# let f (x : 'a) : 'a = x in (f true, (3 : 'a));;
Error: This expression has type int but an expression was expected of 
type bool


Here it is clear that all annotations are talking about the same 
variable 'a. If 'a was existentially bound twice (once for the function 
definition, once for the constant 3), a type error would not occur.

Johannes


  reply	other threads:[~2009-07-29  5:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-28 21:47 Aaron Bohannon
2009-07-28 23:28 ` [Caml-list] " Jon Harrop
2009-07-28 23:04   ` Philippe
2009-07-29  5:38     ` Johannes Kanig [this message]
2009-07-29  7:40 ` Mark Shinwell
2009-07-29 13:41   ` Aaron Bohannon
2009-07-29 14:39     ` Jacques Garrigue
2009-07-29 16:50       ` Aaron Bohannon
2009-07-29 19:01       ` Jon Harrop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A6FE050.2040803@gmail.com \
    --to=johannes.kanig@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=jon@ffconsultancy.com \
    --cc=philippe.veber@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).