Browse thread
[Caml-list] About polymorphic methods and recursive classes
[
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: | Sébastien_Briais <sebastien.briais@e...> |
| Subject: | [Caml-list] About polymorphic methods and recursive classes |
Hello,
(I tried to send this mail yesterday, but apparently it did not work.
So I send it again:)
I tried to encode lists with objects.
I defined a class list which is virtual and that contains only a visit
method
which is polymorphic.
I have defined also a virtual class visitor to visit the lists.
The ocaml toplevel indicated me there was an error in my piece of code
but since I didn't understand the error message, I have simplified my piece
in order to understand which part is not accepted by ocaml.
Here is the simplified code
> ledit ocaml
Objective Caml version 3.06
# class virtual ['a] visitor =
object
method virtual caseNil : 'a
end
and virtual int_list =
object
method virtual visit : 'a.('a visitor -> 'a)
end
;;
class virtual ['a] visitor : object method virtual caseNil : 'a end
class virtual int_list : object method virtual visit : 'a visitor -> 'a end
# class nil =
object
inherit int_list
method visit v = v#caseNil
end
;;
This expression has type 'a visitor
It has no method caseNil
This is this last message that I do not understand.
I tried also to remove the 'and' in the recursive class definitions
(since here, the two classes are not really recursive because I have
removed the caseCons method in the visitor) and ocaml accepts this
modified code.
I tried also to instantiate the 'a type parameter with int (so I have
caseNil:int and visit:visitor->int) and this is also accepted.
Why is my code rejected ? What does mean the error message ?
Thank you
Regards
Sébastien
-------------------
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