caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: Radu Grigore <radugrigore@gmail.com>
Cc: Goswin von Brederlow <goswin-v-b@web.de>,
	Andreas Rossberg <rossberg@mpi-sws.org>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] mutable and polymorphism
Date: Fri, 17 Sep 2010 09:31:01 +0200	[thread overview]
Message-ID: <87aangesi2.fsf@frosties.localdomain> (raw)
In-Reply-To: <AANLkTimdJ7De5FhG=EsG=Tv83msUzMkV_AYhnCHjx=4x@mail.gmail.com> (Radu Grigore's message of "Wed, 15 Sep 2010 20:38:12 +0100")

Radu Grigore <radugrigore@gmail.com> writes:

> On Wed, Sep 15, 2010 at 8:10 PM, Goswin von Brederlow <goswin-v-b@web.de> wrote:
>> In your original a.ml you didn't use the [...]
>
> Let me rephrase. IMO, both the modified a.ml and the modified c.ml
> fail for the same reason: polymorphic references. Therefore, just as
> you can't infer from "modified a.ml fails" that "original a.ml should
> fail" you can also *not* infer from "modified c.ml fails" that
> "original c.ml should fail".
>
>> Because the compiler is stupid and things with a ref can't
>> polymorphic.
>
> The compiler isn't stupid: Polymorphic references are unsound. See for
> example Section 2.2.3 here:
>   http://caml.inria.fr/pub/docs/u3-ocaml/ocaml-core.html#toc8

It isn't as smart as you. Call it conservative.

>> let f y = let x = ref () in (fun y -> ()) y in f 1; f 'a'
>
> This has different semantics. Consider
>   let f y = let x = ref 0 in (fun y -> incr x) y in f 1; f 'a'

Yes it does. Which makes the value restriction sometimes anyoing.

> In any case, I'm more interested in an explanation of what happens,
> since in practice I'm quite happy with a.ml (together with hiding the
> reference from outside by not putting it in mli).
>
> regards,
>   radu

Reading up on value restrictions as mentioned in the other mails will
give you the technical details. But they get quite technical so you
might need some background into the theory of functional languages.

MfG
        Goswin


  parent reply	other threads:[~2010-09-17  7:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-15 17:10 Radu Grigore
2010-09-15 17:40 ` [Caml-list] " Andreas Rossberg
2010-09-15 17:59   ` Radu Grigore
2010-09-15 19:10     ` Goswin von Brederlow
2010-09-15 19:38       ` Radu Grigore
2010-09-15 20:44         ` Kaustuv Chaudhuri
2010-09-17  7:31         ` Goswin von Brederlow [this message]
2010-09-17 14:04 ` Radu Grigore
2010-09-17 14:08   ` Radu Grigore

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=87aangesi2.fsf@frosties.localdomain \
    --to=goswin-v-b@web.de \
    --cc=caml-list@yquem.inria.fr \
    --cc=radugrigore@gmail.com \
    --cc=rossberg@mpi-sws.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).