From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Dawid Toton <d0@wp.pl>
Cc: caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Re: References and polymorphism
Date: Wed, 11 Jan 2012 12:07:24 +0100 [thread overview]
Message-ID: <CAPFanBGAyytgavTmooUChTkEQwLY-Fv9igduas55RN12EPcvPw@mail.gmail.com> (raw)
In-Reply-To: <4F0D6913.4090207@wp.pl>
How would you make the distinction between
let f : 'a . unit -> 'a list ref =
fun () -> ref ([] : 'a list)
and
let f : 'a . unit -> 'a list ref =
let r = ref ([] : 'a list) in
fun () -> r
?
On Wed, Jan 11, 2012 at 11:48 AM, Dawid Toton <d0@wp.pl> wrote:
>> They certainly did: http://mlton.org/ValueRestriction has links to the
>> various papers on the subject (the present scheme was not the first solution
>> for SML, as it notes).
>>
> I don't get one thing about this. It seems that all examples which justify
> the value restriction are unsound just because a ref cell is given too
> general type.
> Why not to just forbid too general 'a ref types? See the example from the
> page cited above (with explicit quantifier added):
>
> let f : forall 'a. 'a -> 'a =
> let r : 'a option ref = ref None in
> fun x -> (* do evil things with the ref cell *)
> let y = !r in
> let () = r := Some x in
> match y with
> | None -> x
> | Some y -> y
>
> The problem is that the 'a variable is bound by a general quantifier and at
> the same time it is used to give a type to the ref cell. But if this were
> forbidden, I see no need for the value restriction at all. For example:
>
> let g : forall 'a. 'a -> 'a =
> fun (x : exists 'b. 'b) ->
> let r : 'b option ref = ref None in
> (* nothing bad can happen *)
> ...
>
> Dawid
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
next prev parent reply other threads:[~2012-01-11 11:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-10 15:29 [Caml-list] " Dario Teixeira
2012-01-10 15:45 ` Romain Bardou
2012-01-10 16:31 ` Arnaud Spiwack
2012-01-10 17:00 ` Dario Teixeira
2012-01-10 17:20 ` David Allsopp
2012-01-10 18:59 ` Gabriel Scherer
2012-01-11 10:48 ` [Caml-list] " Dawid Toton
2012-01-11 11:07 ` Gabriel Scherer [this message]
2012-01-11 13:00 ` Dawid Toton
2012-01-11 13:15 ` rossberg
2012-01-11 13:56 ` Dawid Toton
2012-01-11 15:42 ` rossberg
2012-01-12 9:55 ` Dawid Toton
2012-01-12 10:05 ` Andrej Bauer
2012-01-12 10:46 ` Romain Bardou
2012-01-11 11:43 ` rossberg
2012-01-11 13:34 ` Dawid Toton
2012-01-11 15:34 ` rossberg
2012-01-11 13:57 ` Dawid Toton
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=CAPFanBGAyytgavTmooUChTkEQwLY-Fv9igduas55RN12EPcvPw@mail.gmail.com \
--to=gabriel.scherer@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=d0@wp.pl \
/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