Date: Mon, 9 Feb 1998 14:25:19 +0100 (MET)
From: Simon Helsen <email@example.com>
To: Moreau <firstname.lastname@example.org>
Subject: Re: Re : Weak types ?
> let toto y =
> let id x = x in
> id id y ;;
> this will be of type 'a ->'a
> What is the difference with this :
> let toto = let id x = x in id id ;;
> I thought caml will understand that there is no difference !
> why does caml make this difference ?
Eta-expansion (what you're doing in the first example) indeed solves the
this common degration of polymorphic values to pseudo poly's. The
fundamental reason being the syntactic approach of value polymorhism. The
first example is just syntactic sugar for "let toto = function y -> let id
x = x in id id y" So, toto is defined as a lambda, which is non-expansive
(and this is obvious since this type of declaration can never do something
"wrong" in the sence of polymorphic references, the actual reason value
polymorphism). However, in the 2nd example, the declaration is an
*application* (which of course results in a function, but that's
syntactically not apparent) Hence, the resulting poly value has to degrade
(to avoid potential problems with polymorphic references)
Note that the 2nd example is again invalid Standard ML and there we rely
on eta-expansion to write something like that at all...
Hope this helps,
PS: I know people on this list are Ocaml users, but it might be worth to
look at pages 321-326 (section 8.3) of the reference below. It contains a
fairly good explanation of the problem with poly-references and value
polymorphism. It also gives a brief description of the history of this
"ML for the working programmer -2nd edition", L.C.Paulson, 1996, Cambridge
This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:13 MET