Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2005-06-30 (18:31)
From: Julien Verlaguet <Julien.Verlaguet@p...>
Subject: Re: [Caml-list] bizarre type

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

two things :


# type 'a t=string;;
type 'a t = string
# let g (x : 'a) (y : 'a t)=();;
val g : 'a -> 'a t -> unit = <fun>
# g 3;;
- : int t -> unit = <fun>

here we should have int t=string='_a t ...

second :

I strongly disaggree with the fact that the compiler infered the most 
general type in this case.

Because I specified it.

when you write (let f=fun (x : 'a) (y : 'a) -> (x,y)), you force the type 
of x 
and y to be equal.
It would be a problem if one could write (f true 3).


PS : The behavior with abstract types is the one expected and my example 
in the previous mail was irrelevant (sorry about that).