From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA18548 for caml-redistribution; Sun, 24 May 1998 00:15:03 +0200 (MET DST) 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 EAA26930 for ; Fri, 22 May 1998 04:23:08 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id EAA02528 for ; Fri, 22 May 1998 04:22:52 +0200 (MET DST) Received: from localhost (safran.kurims.kyoto-u.ac.jp [130.54.16.91]) by kurims.kurims.kyoto-u.ac.jp (8.8.8/3.6W) with ESMTP id LAA08371; Fri, 22 May 1998 11:21:51 +0900 (JST) To: tews@tcs.inf.tu-dresden.de Cc: caml-list@inria.fr Subject: Re: Subtype problem In-Reply-To: Your message of "Wed, 20 May 1998 17:00:12 +0200" <199805201500.RAA19129@ithif18.inf.tu-dresden.de> References: <199805201500.RAA19129@ithif18.inf.tu-dresden.de> X-Mailer: Mew version 1.92 on Emacs 20.2 / Mule 3.0 (MOMIJINOGA) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <19980522112157L.garrigue@kurims.kyoto-u.ac.jp> Date: Fri, 22 May 1998 11:21:57 +0900 From: Jacques GARRIGUE X-Dispatcher: imput version 971024 Sender: weis From: Hendrik Tews > Hi, > > could somebody tell me, why > > -------------------------Version 1--------------------------- > class point x = > val mutable x = (x : int) > method x = x > method move (i : int) = {< x = x + i >} > end;; > > class colored_point x c = > val mutable x = (x : int) > val color = (c : int) > method x = x > method move (i : int) = {< x = x + i >} > method color = color > end;; > > let p = ((new colored_point 2 1 :> point) : point) > -------------------------Version 1--------------------------- > > compiles without problem, while > > -------------------------Version 2--------------------------- > class point x = > val mutable x = (x : int) > method x = x > method move (i : int) = Some {< x = x + i >} > end;; > > class colored_point x c = > val mutable x = (x : int) > val color = (c : int) > method x = x > method move (i : int) = Some {< x = x + i >} > method color = color > end;; > > let p = ((new colored_point 2 1 :> point) : point) > -------------------------Version 2--------------------------- > > produces an error? (The only difference is the move method, which > delivers an option in version 2). The error message is Objective Caml's subtyping algorithm does not subtype under type constructors (but it does it under abbreviations), for the sake of efficiency. That is, eventhough colored_point :> point, you don't have colored_point option :> point option. This equation would be needed to check the subtyping in method move of example 2. By the way, Objective Label does it, so that let p = (new colored_point 2 1 : colored_point :> point) would work for the second example. You need to write a complete coercion (with both types), since doing this for partial coercions would lead to huge types, and very slow inference. Jacques --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG