caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Kiselyov Oleg <oleg@okmij.org>
Cc: avatar@hot.ee, jonathan.protzenko@gmail.com,
	OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] typechecking
Date: Sun, 23 Mar 2014 21:59:12 +0900	[thread overview]
Message-ID: <CE9F7F44-8DFE-411F-97C1-9FC0727259BB@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20140323044133.99286.qmail@www1.g3.pair.com>

On 2014/03/23 13:41, oleg@okmij.org wrote:

> The complete solution is to update the function
>        generalize_expansive in typing/ctype.ml
> which is responsible for implementing the relaxed value restriction.
> The type 'a should not be considered co-variant in 'a. Alas, such a
> modification is a bit cumbersome since generalize_expansive is called
> recursively. One have to split cases. It is not clear how much benefit
> can be gained -- complicating type checker for the sake of a rare
> error.

I don't think it would make sense anyway.
I suppose your rationale is that since 'a is empty in the sound part
of the language, if you actually get a value of this type it must be
unsound, and should not be generalized.
However, this would just be a hack, and would not catch all such
errors. For instance 'a list contains the empty list, so we have no reason
not to generalize it, but an unsound function might still return a
non empty list with this type.
Moreover, there are also useful applications of the generalization of 'a.
For instance, the following idiom allows you to give an arbitrary polymorphic
type to a non-value, which you cannot under the strict value restriction.

	let y = Obj.magic (f x)
	let z : ('a -> 'a) t = y

So well, unsound functions are unsound, and you have to live with that.
In particular _always_ annotate with ground types.

Jacques Garrigue

  reply	other threads:[~2014-03-23 12:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-22 20:02 Misha Aizatulin
2014-03-22 20:40 ` Daniel Bünzli
2014-03-22 22:12   ` Yaron Minsky
2014-03-22 22:24     ` Jonathan Protzenko
2014-03-23  4:41 ` oleg
2014-03-23 12:59   ` Jacques Garrigue [this message]
2014-03-24  8:46     ` Alain Frisch

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=CE9F7F44-8DFE-411F-97C1-9FC0727259BB@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=avatar@hot.ee \
    --cc=caml-list@inria.fr \
    --cc=jonathan.protzenko@gmail.com \
    --cc=oleg@okmij.org \
    /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).