Version française
Home     About     Download     Resources     Contact us    
Browse thread
type error
[ 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@m...>
Subject: Re: [Caml-list] type error
From: "Jacques Le Normand" <rathereasy@gmail.com>
> thanks for all the help so far; it's been very educational
> there's a type error I can't get my head around:
> 
> 
> class a =
> object
> end
> 
> and b =
> object
>   inherit a
>   method d (e : b) = (e :> a)
> end
> 
> 
> gives the error:
> 
> The abbreviation b expands to type < d : b -> a > but is used with type <  >
> 
> why is this?

You cannot coerce to a type that is not yet (fully) defined.
In practice, what happens is that (e :> a) is just interpreted as
(e : a), so that you are unifying a and b, with the above error.

As an exception to the above rule, you can coerce self toward the
currently defined class (i.e. coerce self to a inside a), but only if
self is covariant in itself. Here you coerce b to a inside b, so this
doesn't apply.

Jacques Garrigue