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





Le 29 juil. 09 à 01:28, Jon Harrop <jon@ffconsultancy.com> a écrit :

> On Tuesday 28 July 2009 22:47:25 Aaron Bohannon wrote:
>> let f (x : 'a) : 'a = x in (f true, f 3);;
>
> Err, good question. :-)
>
> # let f : _ = fun x -> x in f true, f 3;;
> - : bool * int = (true, 3)
The type of f here is something like 'a. 'a -> 'a. So you can use it  
on bool or int. I understand it like [], like in the expression (3 ::  
[], true :: []) where it has type 'a. 'a list (unfortunately it is not  
synctacally correct to say
let f : 'a. 'a -> 'a = fun x -> x, I don't know why.)

>
> # let f : 'a = 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  
return type of f and which should unify with both bool and int. Hence  
the typing error.


>
>
> 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).

HTH,

Ph.

>
>
> Any takers?
>
> -- 
> 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


  reply	other threads:[~2009-07-28 23:05 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 [this message]
2009-07-29  5:38     ` Johannes Kanig
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=A364D077-4ABE-4CDC-A4D1-B56A5738F60A@googlemail.com \
    --to=philippe.veber@googlemail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=jon@ffconsultancy.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).