From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 921DFBB9C for ; Mon, 19 Sep 2005 14:20:20 +0200 (CEST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j8JCKI77007101 for ; Mon, 19 Sep 2005 14:20:19 +0200 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j8JCK7HT013721; Mon, 19 Sep 2005 21:20:08 +0900 (JST) Date: Mon, 19 Sep 2005 21:20:59 +0900 (JST) Message-Id: <20050919.212059.41628279.garrigue@math.nagoya-u.ac.jp> To: micha-1@fantasymail.de Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] object type error From: Jacques Garrigue In-Reply-To: <200509191044.36763.micha-1@fantasymail.de> References: <200509191044.36763.micha-1@fantasymail.de> X-Mailer: Mew version 4.2 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 432EAD02.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 implements:01 inference:01 unifying:01 annotation:01 occurences:01 polymorphic:01 defining:01 inherit:01 expression:01 expression:01 coercion:01 jacques:01 jacques:01 defined:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.4 required=5.0 tests=DNS_FROM_RFC_ABUSE autolearn=disabled version=3.0.3 From: Michael Wohlwend > ( type xxx is a class type and the other class implements this interface) > > ----------------------Error: > This expression has type > < (* many methods *); .. > > but is here used with type xxx > Self type cannot be unified with a closed object type > --------------------- > I try to get rid of them by adding random type declarations which I mostly > don't understand :-), but that's not the solution. > > What is the reason for that message? It means that type inference results in unifying the type of self (either from a named self, a {< .. >} expression, or a type annotation) to an explicit object type. To allow classes to be extended, the type of self must be left polymorphic. You can sometimes avoid it by using a coercion (self :> xxx), but this doesn't work if xxx was not defined in advance, of if it contains contravariant occurences. I stop here: you already realize this is a rather hairy problem. Since there can be many causes, I need to see your code to understand where the problem comes from. Another solution if you don't need to inherit from the object you are defining, is to use an immediate object, as it is allowed to have a closed type; at least you won't get the above message. Jacques Garrigue