caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Type generalization confusion
@ 2017-05-08 18:32 Reed Wilson
  2017-05-09  3:49 ` Gabriel Scherer
  0 siblings, 1 reply; 8+ messages in thread
From: Reed Wilson @ 2017-05-08 18:32 UTC (permalink / raw)
  To: caml-list

[-- 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 --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-05-10 18:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-08 18:32 [Caml-list] Type generalization confusion Reed Wilson
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

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