caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Leo White <leo@lpw25.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Type generalization confusion
Date: Tue, 09 May 2017 04:54:48 -0400	[thread overview]
Message-ID: <1494320088.2074838.970492485.42DF8438@webmail.messagingengine.com> (raw)
In-Reply-To: <CALLFq5Q-jTxfTUKaR2hT32y7qhcGqVUA87osY5fyg47eDS=D=w@mail.gmail.com>

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

> But this similar type has no problem:
>  type 'a field = Int of int
>  let a = Int 3
>  let b = Int (1 + 2)

This is the relaxed value restriction: `field` is covariant in it's
parameter which means that the type variable is only used in
covariant positions and so can be generalized even though the
expression is not a value.
> Both a and b receive the same generalized type. Why does the GADT
> style prevent this from occuring?
 OCaml currently just assumes that types defined with GADT syntax are
 invariant because checking of variance with GADTs is more difficult. If
 you annotate your type as covariant then it behaves the same:
  type +_ field = Int : int -> 'a field
  let a = Int 3
  let b = Int (1 + 2)

gives:

  type +_ field = Int : int -> 'a field
  val a : 'a field = Int 3
  val b : 'a field = Int 3

Regards,

Leo



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

  reply	other threads:[~2017-05-09  8:54 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
2017-05-09  5:43   ` Reed Wilson
2017-05-09  8:54     ` Leo White [this message]
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=1494320088.2074838.970492485.42DF8438@webmail.messagingengine.com \
    --to=leo@lpw25.net \
    --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).