Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re : Weak types ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Simon Helsen <helsen@i...>
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,

Simon

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
problem:

"ML for the working programmer -2nd edition", L.C.Paulson, 1996, Cambridge
University Press