Re: Re : Weak types ?

From: Simon Helsen (
Date: Mon Feb 09 1998 - 14:25:19 MET

Date: Mon, 9 Feb 1998 14:25:19 +0100 (MET)
From: Simon Helsen <>
To: Moreau <>
Subject: Re: Re : Weak types ?
In-Reply-To: <01bd3330$064565a0$>
Message-Id: <Pine.A32.3.96.980209141030.14334E-100000@marvin>

> 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
University Press

This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:13 MET