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

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Andrej Bauer <Andrej.Bauer@f...>
Subject: Re: [Caml-list] Type issue
Here's a simpler example:

# fun (g, x) -> (g true, g x) ;;
- : (bool -> 'a) * bool -> 'a * 'a = <fun>

Even though it looks like g could be of type 'b -> 'a, ocaml decides to 
go with bool only. I see this on the mailing list every once in a while, 
but I always forget the reasoning behind it.

If I had to guess, it's just a result of unification algorithm in type 
reconstruction (which, incidentally I thought in class 20 minutes 
ago...). Starting from

g : 'b -> 'a
x : 'c

we get these equations:

'b = bool    because true must have type 'b
'c = 'b      because x must have type 'b

And now we get 'b = 'c = bool, hence the result.

Andrej