Re: Typing-problem

From: Jean-Christophe Filliatre (filliatr@lri.fr)
Date: Mon May 31 1999 - 12:37:39 MET DST


From: Jean-Christophe Filliatre <filliatr@lri.fr>
Date: Mon, 31 May 1999 12:37:39 +0200 (MEST)
To: aXl <krauth@fmi.uni-passau.de>
Subject: Re: Typing-problem
In-Reply-To: <Pine.GSO.3.96.990530171304.16161A-100000@kosh>

> why is in the following example b of type "string -> string" ?
>
> let a = id id;;
> let b = a;;
> a "foo";;
> (* until here it's covered by the faq's *)
> b;;

It is because:

  1. the type variable is not generalized is the type of a;
     (it is '_a -> '_a)

  2. that type variable is shared between the types of a and b

Therefore when applying a to "foo", that type variable is instanciated
by string, which instanciates also the type of b.

A more detailed explanation is given here :

  http://caml.inria.fr/pub/old_caml_site/FAQ/FAQ_EXPERT-eng.html#polymorphisme

Best regards,

-- 
Jean-Christophe FILLIATRE
  mailto:Jean-Christophe.Filliatre@lri.fr
  http://www.lri.fr/~filliatr



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