caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Andreas Rossberg <rossberg@mpi-sws.org>
To: Radu Grigore <radugrigore@gmail.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] mutable and polymorphism
Date: Wed, 15 Sep 2010 19:40:19 +0200	[thread overview]
Message-ID: <B86B93AA-FD40-4A5D-831F-4AE99D433D8C@mpi-sws.org> (raw)
In-Reply-To: <AANLkTimOrmnhFmzgDBVO5ZgPKF89ePHBnHqf=w+2Fynu@mail.gmail.com>

On Sep 15, 2010, at 19:10, Radu Grigore wrote:
> Compile the following three files one-by-one.
>  (*a.ml*) let _ = ref () in let f = fun _ -> () in f 1; f 'a'
>  (*b.ml*) let f = let _ = () in fun _ -> () in f 1; f 'a'
>  (*c.ml*) let f = let _ = ref () in fun _ -> () in f 1; f 'a'
> The files a.ml and b.ml compile; the file c.ml fails with
>  Error: This expression has type char
>    but an expression was expected of type int
> Could someone explain why having a mutable field ("contents" in this
> case) restricts the polymorphism of f?

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'


/Andreas


  reply	other threads:[~2010-09-15 17:40 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 ` Andreas Rossberg [this message]
2010-09-15 17:59   ` [Caml-list] " 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
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=B86B93AA-FD40-4A5D-831F-4AE99D433D8C@mpi-sws.org \
    --to=rossberg@mpi-sws.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=radugrigore@gmail.com \
    /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).