caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Didier Remy <Didier.Remy@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] The value restriction
Date: Fri, 16 Dec 2011 11:16:26 +0100	[thread overview]
Message-ID: <4EEB1A7A.6030906@inria.fr> (raw)
In-Reply-To: <CAPFanBFAXSwx3j35Jhbi-eaCAK1h6BP+TU25BvkE5xM1Qr0psQ@mail.gmail.com>

On 12/16/2011 10:39 AM, Gabriel Scherer wrote:
> 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.

Yes, this is the reason.

The only influence of the second component is that the pair itself is not a
value, in both cases.  The differences you observed is only due to the
differences in the (types of the) first component.

Perhaps, you expected that the type of first component of the pair could be
generalized in both cases because it is a value.

There is a known improvement of the value restriction that would allow this
generalization: the rule would say "type variables appearing in the type of
*expansive* expressions cannot be generalized".  Intuitively, expansive
expressions are expressions whose evaluation could allocate a piece of
mutable store.  In the example above the pair itself is non expansive (it is
a constructor), the first component is not expansive (it is a value); only
the second component is expansive (it is an application).  Hence, only type
variables appearing in the second component cannot be generalized.

However, this improvement is not implemented in OCaml.

         Didier



      reply	other threads:[~2011-12-16 10:16 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
2011-12-16 10:16   ` Didier Remy [this message]

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=4EEB1A7A.6030906@inria.fr \
    --to=didier.remy@inria.fr \
    --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).