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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andreas Rossberg <rossberg@p...>
Subject: Re: [Caml-list] bizarre type
Julien Verlaguet wrote:
> I would like to know if the following behavior is normal :
> 
> type 'a t=string ;;
> 
> # let g (x : 'a t) (y : 'a)=();;
> val g : 'a t -> 'a -> unit = <fun>
> 
> # g ("hello" : int t);;
> - : '_a -> unit = <fun>
> 
> I was expecting: (int -> unit).

Since

   int t = string = '_a t

or more generally,

   x t = y t

for any x and y, your type annotation does not induce anything about the 
instantiation of g's variable 'a. The following is perfectly legal:

   g ("hello" : int t) true

The compiler just infers the most general type.

Cheers,

   - Andreas

-- 
Andreas Rossberg, rossberg@ps.uni-sb.de

Let's get rid of those possible thingies!  -- TB