From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Reed Wilson <cedilla@gmail.com>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Type generalization confusion
Date: Mon, 8 May 2017 20:49:49 -0700 [thread overview]
Message-ID: <CAPFanBHJsRy1YXsHJpL66BDr4pq-BSc=Pdk=8Tg+uQ98ogKnfA@mail.gmail.com> (raw)
In-Reply-To: <CALLFq5SVR_mLGkof-CF4T1ud_qZn0-YKU4O-4OpeWiGNnRGiRQ@mail.gmail.com>
This is the value restriction at work: only values are generalized
(often of the form "fun x -> ..."), and while (Int 3) is a value, (Int
(1 + 2)) is not.
On Mon, May 8, 2017 at 11:32 AM, Reed Wilson <cedilla@gmail.com> wrote:
> I've been working with some of the new features introduced with GADTs, and
> ran into a confusing instance of the "type variables that cannot be
> generalized" error.
>
> The simplified program is as follows:
> type _ field = Int : int -> 'a field
> let a = Int 3
> let b = Int (1 + 2)
> let inside = 1 + 2
> let c = Int inside
>
> ocamlc -i returns:
> type _ field = Int : int -> 'a field
> val a : 'a field
> val b : '_a field
> val inside : int
> val c : 'a field
>
> with b remaining non-generalized. The problem I'm having with it is that the
> type variable doesn't depend on the value at all, so I don't see how that
> can prevent generalization.
>
> Also, the manual says the reason some types aren't generalized is due to
> "polymorphic mutable data structures". Nothing I created is mutable, so why
> was generalization turned off in the first place?
>
> Finally, I'm confused why separating the function from the definition is
> enough to fix this; c is generalized simply by defining 1+2 in a separate
> value (which must be global, apparently).
>
> Thanks,
> Reed Wilson
>
> --
> ç
next prev parent reply other threads:[~2017-05-09 3:50 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-08 18:32 Reed Wilson
2017-05-09 3:49 ` Gabriel Scherer [this message]
2017-05-09 5:43 ` Reed Wilson
2017-05-09 8:54 ` Leo White
2017-05-09 19:56 ` Reed Wilson
2017-05-09 20:54 ` Jeremy Yallop
2017-05-10 18:14 ` Reed Wilson
2017-05-10 13:29 ` Mikhail Mandrykin
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='CAPFanBHJsRy1YXsHJpL66BDr4pq-BSc=Pdk=8Tg+uQ98ogKnfA@mail.gmail.com' \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@inria.fr \
--cc=cedilla@gmail.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