[
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: | Didier Remy <Didier.Remy@i...> |
| Subject: | Re: [Caml-list] functional objects |
> What would that look like in the multiple inheritance case?
Why did you not ask this in the first place? (i.e. if you meant
multiple inheritance, you should have provided an example with multiple
inheritance).
Have you really tried this exercise yourself before asking for help? The
pattern seemed simple enough so that its generalization was obvious.
Didier Rémy
class ['a1] c1 (x1 : 'a1) = object
val x1_ = x1
method m1 = ()
method c1 x1 = {< x1_ = x1 >}
end;;
class ['a2] c2 (x2 : 'a2) = object
val x2_ = x2
method m2 = ()
method c2 x2 = {< x2_ = x2 >}
end;;
class ['a1,'a2, 'a3] c3 x1 x2 (x3 : 'a3) = object
inherit ['a1] c1 x1
inherit ['a2] c2 x2
val x3_ = x3
method m3 = ()
method c3 x1 x2 x3 = ({< x3_ = x3 >} # c1 x1) # c2 x2
end;;
(* Note that fields are overriden in the reverse order, which does not
matter since they are all disjoint. Should method c1 and c2 both override
the same parent field, then the order should be enforced, as follows: *)
class ['a1,'a2, 'a3] c3 x1 x2 (x3 : 'a3) = object (self)
inherit ['a1] c1 x1
inherit ['a2] c2 x2
val x3_ = x3
method m3 = ()
method private c3_ x3 = {< x3_ = x3 >}
method c3 x1 x2 x3 = ((self # c1 x1) # c2 x2) # c3_ x3
end;;
-------------------
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