From: Philippe Wang <philippe.wang.lists@gmail.com>
To: Andrej Bauer <andrej.bauer@andrej.com>
Cc: Jacques Le Normand <rathereasy@gmail.com>,
caml-list caml-list <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Re: value restriction
Date: Sun, 3 Jan 2010 00:09:50 +0100 [thread overview]
Message-ID: <4d1b2df21001021509n70a98f23yf444f2e358276a69@mail.gmail.com> (raw)
In-Reply-To: <7d8707de1001020846s29332a67j21878751ed3da22@mail.gmail.com>
On Sat, Jan 2, 2010 at 5:46 PM, Andrej Bauer <andrej.bauer@andrej.com> wrote:
>> on another note (but staying very much on the same topic), why won't the
>> following generalize:
>> # let foo =
>> let counter = ref 0 in
>> let bar = !counter in
>> let baz = fun x -> bar
>> in
>> baz
>>
>> val foo : '_a -> int = <fun>
>
> It's even worse:
>
> Objective Caml version 3.11.1
>
> # let _ = ref () in fun x -> x ;;
> - : '_a -> '_a = <fun>
>
> I am sure this makes sense in France. Happy new year!
>
> Andrej
The idea is to prevent potentially wrong programs.
It is bad to write (let x = ref [ ] in x := ["hello"] ; x := [2]).
So the algorithm — that prevents the generalization process of
expressions such as (ref [ ]) — prevents the generalization of all
application expressions. (actually, almost all because I think there
are a few exceptions such as # let f = let x = ref [] in !x ;; val f :
'a list = []).
Making a perfect algorithm that generalizes only and always when
permitted is very hard (maybe it's impossible because not decidable?).
This example shows a program that is rejected because its type is not
computable in Caml's type system :
(fun x -> x x) (fun x -> x) (fun x -> x)
It could be a valid program (i.e. it wouldn't lead to a type crash at
runtime), but it is rejected because the type system is not capable of
asserting its correctness.
(I am not certain I am not off topic)
Cheers,
--
Philippe Wang
mail@philippewang.info
next prev parent reply other threads:[~2010-01-02 23:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-01 23:05 Jacques Le Normand
2010-01-02 16:25 ` Jacques Le Normand
2010-01-02 16:46 ` [Caml-list] " Andrej Bauer
2010-01-02 23:09 ` Philippe Wang [this message]
2010-01-03 0:30 ` Kaustuv Chaudhuri
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=4d1b2df21001021509n70a98f23yf444f2e358276a69@mail.gmail.com \
--to=philippe.wang.lists@gmail.com \
--cc=andrej.bauer@andrej.com \
--cc=caml-list@yquem.inria.fr \
--cc=rathereasy@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