caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Andrej Bauer <andrej.bauer@andrej.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] The value restriction
Date: Fri, 16 Dec 2011 10:39:26 +0100	[thread overview]
Message-ID: <CAPFanBFAXSwx3j35Jhbi-eaCAK1h6BP+TU25BvkE5xM1Qr0psQ@mail.gmail.com> (raw)
In-Reply-To: <CAB0nkh082KBYgxJHZ9jb=g3Nb5PSaXX26ZzQs8N3zCtQBpEm3g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1834 bytes --]

The following example, derived from yours, is probably more surprised (I
didn't understand your issue at first):

  # ((fun a -> a), (fun b -> b));;
  - : ('a -> 'a) * ('b -> 'b) = (<fun>, <fun>)
  # ((fun a -> a), (fun b -> b) (fun c -> c));;
  - : ('_a -> '_a) * ('_b -> '_b) = (<fun>, <fun>)

Here is how I explain this from the paper "Relaxing the value restriction",
Jacques Garrigue, 2004:
  http://caml.inria.fr/about/papers.en.html
No guarantee that this matches the actual typing behavior.

There are two different typing rules: one for the form "let x = v in e",
where a value is bound, all typing variables are generalized, and one other
for the form "let x = e1 in e2", where an *expression* is bound, and all
non-negative variables are generalized.

In the ((fun a -> a), (fun b -> b)) example, this is a value, everything
gets generalized. In the ((fun a -> a), (fun b -> b) (fun c -> c)) example,
this is not a value anymore, and both components use a type variable in
negative position, so nothing gets generalized. In the ([], (fun b -> b)
(fun c -> c)) example, this is not a value but [] is covariant in its type
variable, so it still gets generalized.


On Fri, Dec 16, 2011 at 10:18 AM, Andrej Bauer <andrej.bauer@andrej.com>wrote:

> Can someone explain this behavior?
>
> # ([], (fun x -> x) (fun y -> y)) ;;
> - : 'a list * ('_b -> '_b) = ([], <fun>)
>
> # ((fun a -> a), (fun x -> x) (fun y -> y)) ;;
> - : ('_a -> '_a) * ('_b -> '_b) = (<fun>, <fun>)
>
> Why does the second component influence the first one (in a non-obvious
> way)?
>
> With kind regards,
>
> Andrej
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>

[-- Attachment #2: Type: text/html, Size: 2736 bytes --]

  reply	other threads:[~2011-12-16  9:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16  9:18 Andrej Bauer
2011-12-16  9:39 ` Gabriel Scherer [this message]
2011-12-16 10:16   ` Didier Remy

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=CAPFanBFAXSwx3j35Jhbi-eaCAK1h6BP+TU25BvkE5xM1Qr0psQ@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=andrej.bauer@andrej.com \
    --cc=caml-list@inria.fr \
    /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).