Version française
Home     About     Download     Resources     Contact us    
Browse thread
Typing-problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jean-Christophe Filliatre <filliatr@l...>
Subject: Re: Typing-problem

> 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/FAQ/FAQ_EXPERT-eng.html#polymorphisme

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