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
[Caml-list] Re: OCAML Downcasting?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-09-21 (09:50)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] Re: OCAML Downcasting?
From: skaller <>
> On Tue, 2004-09-21 at 19:15, Jacques GARRIGUE wrote:
> > class ['a] button = object (self)
> >   inherit ['a] widget
> >   method raw = `Button (self :> 'a button)
> >   method press = prerr_endline "pressed"
> > end
> > Without the self-cast, you cannot extend any class.
> Is that an issue with classes or polymorphic variants?

With classes.
If you omit the coercion, any class inheriting from button would have
the type of the raw method specialized to itself, and as a result it
would be incompatible with button.

But strangely enough, some tests show that this is not the case. Even
without the coercion, the type of `Button becomes fixed to 'a button.
Looks like there is a bug in the interaction between classes and
variants. So do not forget the coercion even if it works now

Jacques Garrigue

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: