From: Reed Wilson <cedilla@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Type generalization confusion
Date: Mon, 8 May 2017 11:32:02 -0700 [thread overview]
Message-ID: <CALLFq5SVR_mLGkof-CF4T1ud_qZn0-YKU4O-4OpeWiGNnRGiRQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]
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
--
ç
[-- Attachment #2: Type: text/html, Size: 1483 bytes --]
next reply other threads:[~2017-05-08 18:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-08 18:32 Reed Wilson [this message]
2017-05-09 3:49 ` Gabriel Scherer
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=CALLFq5SVR_mLGkof-CF4T1ud_qZn0-YKU4O-4OpeWiGNnRGiRQ@mail.gmail.com \
--to=cedilla@gmail.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