[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Damien Pous <Damien.Pous@e...> |
| Subject: | [Caml-list] Re: OCAML Downcasting? |
Hello,
Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp> wrote:
> Just for fun, here is an example of the second approach:
>
> class virtual ['a] widget = object
> method virtual raw : 'a
> end
> class ['a] button = object (self)
> inherit ['a] widget
> method raw = `Button self
> method press = prerr_endline "pressed"
> end
How to write a signature for this code ?
even "ocamlc -i" fails !
<<
#ocamlc -i error.ml
class virtual ['a] widget : object method virtual raw : 'a end
class ['a] button :
object ('b)
constraint 'a = [> `Button of 'b ]
method press : unit
method raw : 'a
end
>>
then
<<
#ocamlc -c error.ml
The implementation error.ml does not match the interface error.cmi:
Class declarations do not match:
class ['a] button :
object ('b)
constraint 'a = [> `Button of 'b ]
method press : unit
method raw : 'a
end
does not match
class ['a] button :
object
constraint 'a = [> `Button of 'a button ]
method press : unit
method raw : 'a
end
One type parameter has type
[> `Button of < press : unit; raw : 'a; .. > as 'b ] as 'a
but is expected to have type [> `Button of 'c button ] as 'c
Type 'b is not compatible with type 'c button = < press : unit; raw : 'c >
>>
thanks,
Damien
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners