Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Recursive classes and subtyping
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] Recursive classes and subtyping
From: Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>

>  Obviously, I was a bit too quick! I think that the trick works only up to
>  the point where the mutual recursion is fake. This is a slightly more
>  complex example:
> 
> # type -'a t;;
> 
> # let f (x : [> `A] t) = (x : [`A] t);;
> val f : [ `A] t -> [ `A] t = <fun>

If you just put two annotations, they will be unified.
You need an explicit coercion to get the type you expect:

# let f x = (x : [> `A] t :> [`A] t);;
val f : [> `A] t -> [ `A] t = <fun>

Jacques Garrigue
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr