Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
mutable and polymorphism
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Radu Grigore <radugrigore@g...>
Subject: Re: [Caml-list] mutable and polymorphism
On Wed, Sep 15, 2010 at 8:10 PM, Goswin von Brederlow <> wrote:
> In your original you didn't use the [...]

Let me rephrase. IMO, both the modified and the modified
fail for the same reason: polymorphic references. Therefore, just as
you can't infer from "modified fails" that "original should
fail" you can also *not* infer from "modified fails" that
"original 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:

> 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'

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