Re: Re : Weak types ?

From: Pascal Cuoq (Pascal.Cuoq@ens-lyon.fr)
Date: Mon Feb 09 1998 - 15:21:56 MET


From: Pascal Cuoq <Pascal.Cuoq@ens-lyon.fr>
Message-Id: <199802091421.PAA07076@vaise.ens-lyon.fr>
Subject: Re: Re : Weak types ?
To: lyclaire@ac-grenoble.fr
Date: Mon, 9 Feb 1998 15:21:56 +0100 (MET)
In-Reply-To: <01bd3330$064565a0$739536c1@pluton.ac.grenoble.fr> from "Moreau" at Feb 6, 98 07:49:10 pm

> 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 ?

the same examples, rewritten:

let id = fun x -> x ;;

let toto = fun y -> id id y ;;

caml: ha, I know the answer to this one : toto is a function.
The evaluation of "fun y -> anything" can not create references,
so type variables can safely be generalized.

let toto = id id ;;

caml: hmmm, I wonder what this toto may be... It is the result
of an application, and I don't know whether I am qualified to
look deeper into the code to check about that. It might be
anything, I'd better not generalize variables.

About this algorithm, you can think of Caml as of
Winnie-the-Pooh : it can answer difficult questions in the
particular cases where the answer is obvious (ie, syntactic).
Otherwise it doesn't know.

Pascal



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