From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA17579 for caml-red; Thu, 11 Jan 2001 10:23:36 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA14433 for ; Wed, 10 Jan 2001 20:58:29 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f0AJwTT17716 for ; Wed, 10 Jan 2001 20:58:29 +0100 (MET) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id f0AJwSM11322 ; Wed, 10 Jan 2001 20:58:28 +0100 (CET) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id UAA21415 ; Wed, 10 Jan 2001 20:58:28 +0100 (MET) Date: Wed, 10 Jan 2001 20:58:27 +0100 (MET) From: Alain Frisch To: Mattias Waldau cc: Caml-List Subject: Re: Why can't I use val mover : < move : int -> unit; .. > list -> unit ? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis@pauillac.inria.fr 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