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 TAA04452 for caml-red; Wed, 10 Jan 2001 19:53:08 +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 NAA20928 for ; Wed, 10 Jan 2001 13:40:04 +0100 (MET) Received: from tor.abc.se (ns.abc.se [195.17.72.11]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f0ACe3T10890 for ; Wed, 10 Jan 2001 13:40:03 +0100 (MET) Received: from gateway (dialup-46 [195.17.73.46]) by tor.abc.se (8.9.3+Sun/8.9.3) with SMTP id NAA19039 for ; Wed, 10 Jan 2001 13:40:01 +0100 (MET) From: "Mattias Waldau" To: "Caml-List" Subject: Why can't I use val mover : < move : int -> unit; .. > list -> unit ? Date: Wed, 10 Jan 2001 13:39:47 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal Sender: weis@pauillac.inria.fr 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? /mattias (* let _ = mover [p;q] This expression has type p1d_1 = < move : int -> unit > but is here used with type p1d_2 = < move : int -> unit; only_here : int -> int > Only the second object type has a method only_here *) class p1d_1 = object val mutable x = 0 method move d = x <- x + d end class p1d_2 = object val mutable x = 0 method move d = x <- x + d method only_here x = x + x end let main x = x#move 3 let q = new p1d_1 let p = new p1d_2 let _ = main q let _ = main p let mover l = List.iter (fun x -> x#move 10) l (* let _ = mover [p;q] *) (* class p1d_1 : object val mutable x : int method move : int -> unit end class p1d_2 : object val mutable x : int method move : int -> unit method only_here : int -> int end val main : < move : int -> 'a; .. > -> 'a = val q : p1d_1 = val p : p1d_2 = val mover : < move : int -> unit; .. > list -> unit = *)