From: Radu Grigore <radugrigore@gmail.com>
To: Andreas Rossberg <rossberg@mpi-sws.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] mutable and polymorphism
Date: Wed, 15 Sep 2010 18:59:01 +0100 [thread overview]
Message-ID: <AANLkTi=-iuKEJeJbfyDJLbCzUCVF9i-0M8Ev8ohvm=w+@mail.gmail.com> (raw)
In-Reply-To: <B86B93AA-FD40-4A5D-831F-4AE99D433D8C@mpi-sws.org>
On Wed, Sep 15, 2010 at 6:40 PM, Andreas Rossberg <rossberg@mpi-sws.org> wrote:
> Have a look at this variant of c.ml and its "potential" if it type-checked:
>> let f = let xs = ref [] in fun x -> xs := x :: !xs in f 1; f 'a'
Interesting. If I would be a type checker, here's what I'd do.
1. "ref []" tells me that (xs : '_a), because I know refs can't be polymorphic.
2. "x :: !xs" tells me that (xs : '_a list) and (x : '_a)
3. "x -> x :: !xs" tells me that (f : '_a -> '_a list)
4. "f 1" tells me that (f : int -> int list)
5. "f 'a'" tells me... OOPS
Moreover, I'd have similar thoughts about a variant of a.ml (and a.ml
does typecheck!)
let xs = ref [] in let f = fun x -> xs:=x::!xs in f 1; f 'a'
On the other hand, here's what I'd do for the original c.ml, which
with a few names added is
let f = let x = ref () in fun y -> () in f 1; f 'a'
1. "ref ()" tells me that (x : unit ref)
2. "y -> ()" tells me that (f : 'a -> unit)
3. "f 1" returns ()
4. "f 'a'" return ()
In other words, I would have thought that in your example the problem
is that you tried to use a polymorphic reference. (And this problem
even appears in the FAQ.)
regards,
radu
next prev parent reply other threads:[~2010-09-15 17:59 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 [this message]
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
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='AANLkTi=-iuKEJeJbfyDJLbCzUCVF9i-0M8Ev8ohvm=w+@mail.gmail.com' \
--to=radugrigore@gmail.com \
--cc=caml-list@yquem.inria.fr \
--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