[
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: | Jerome Vouillon <vouillon@c...> |
| Subject: | Re: Questions about class types |
Hello, > In ocaml I could hide all the additional objects in a module > implementation. But so far it is not possible to hide methods via > signature matching. It is definitively not possible to hide methods in a class. When a method is redefined, it must keep the same type. The reason is that other methods of the same class might invocate it, and thus expect it to have a certain type. But if a method were hidden, its previous type would also be hidden, and there would be no way to enforce a redefinition of this method to have the right type. > But I still don't understand the type error I got: > > Values do not match: > val newb : unit -> b > is not included in > val newb : unit -> < init : unit; .. > > > If b does not match < init : unit; .. > then the type cast in > > # let newb () : < init : unit; .. > = ((new b ()) : < init : unit; .. >) > > should produce an error. On the other side if the type cast is > valid, then the types should match. Type < init : unit; .. > is more general than type b = < init : unit; f : unit > (the ellipsis is an unamed type variable). So, your type cast produces no error (these two types can be unified), but you cannot expect a function of type unit -> b to be considered as having the more general type unit -> < init : unit; .. >. Regards, Jerome