Browse thread
Why can't I use val mover : < move : int -> unit; .. > list -> unit ?
[
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: | Alain Frisch <frisch@c...> |
| Subject: | Re: Why can't I use val mover : < move : int -> unit; .. > list -> unit ? |
On Wed, 10 Jan 2001, Mattias Waldau wrote: > In the example below I have two separate classes with no common > super class. Both classes have a method 'move'. > > I have no problem using the function main below that can an > arbitrary 'objects with move defined'. However, when I try to > expand the example to list of objects with move defined, I > cannot use this function. > > How can I use the function 'mover'? How do I coerce to > objects with move defined? The problem is that you can't put objects of different types in the same list, and there is no implicit coercion to a subtype in OCaml. As explained in the manual (section 3.10), you have to use an explicit subtyping, for instance: mover [(p :> p1d_1); q] or: type m = < move : int -> unit > mover [(p :> m); (q :> m)] -- Alain Frisch