Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Delegation based OO
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Kenneth Knowles <kknowles@b...>
Subject: Re: [Caml-list] Delegation based OO

> class *type* does_something = object ... end
> 
> class does_more (an_object:#does_something) = object
>    delegates an_object
>    ...
> end
> 
> "an_object" may have a method, say, "an_object#foo : int".
> "does_more" could overwrite the method, and define "does_more#foo :
> float".  Now, what type should "self#pooh" have in the definition of
> an_object?

This is a type error, just as if you override a class method with one of a
different type:

# class x = object method y = 3 end;;
class x : object method y : int end
# class y = object inherit x method y = 4 end;;
class y : object method y : int end
# class z = object inherit x method y = "hello" end;;
This expression has type string but is here used with type int

The same strictness could be applied to delegation.

Kenn

-------------------
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