From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id F2DBEBB81 for ; Thu, 6 Jan 2005 01:24:08 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j060O8oO026206 for ; Thu, 6 Jan 2005 01:24:08 +0100 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 BAA30412 for ; Thu, 6 Jan 2005 01:24:07 +0100 (MET) 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 j060O55A010795 for ; Thu, 6 Jan 2005 01:24:07 +0100 Received: from localhost (suiren [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.13.1/8.13.1) with ESMTP id j060O3af028041; Thu, 6 Jan 2005 09:24:04 +0900 (JST) Date: Thu, 06 Jan 2005 09:24:13 +0900 (JST) Message-Id: <20050106.092413.25912872.garrigue@math.nagoya-u.ac.jp> To: Christophe.Troestler@umh.ac.be Cc: caml-list@inria.fr Subject: Re: [Caml-list] The universal variable 'a would escape its scope From: Jacques Garrigue In-Reply-To: <20050105.191433.84857869.Christophe.Troestler@umh.ac.be> References: <20050105.191433.84857869.Christophe.Troestler@umh.ac.be> X-Mailer: Mew version 4.1 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 concorde with ID 41DC8528.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41DC8525.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 christophe:01 troestler:01 christophe:01 troestler:01 umh:01 expression:01 workaround:01 scope:01 scope:01 jacques:01 jacques:01 constraint:01 caml:02 variant:02 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: From: Christophe TROESTLER > I got a variant of the error > http://caml.inria.fr/archives/200207/msg00110.html and I do not > understand it. Here is a small example showing it: > > # type 'a t = < output : (string -> unit) -> unit; .. > as 'a;; > type 'a t = 'a constraint 'a = < output : (string -> unit) -> unit; .. > > > # class a = object > method f : 'a. 'a t -> unit = fun o -> o#output print_string > end;; > method f : 'a. 'a t -> unit = fun o -> o#output print_string > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > This expression has type < output : (string -> unit) -> unit; .. > > but is here used with type < output : (string -> unit) -> unit; .. > > The universal variable 'a would escape its scope > > Is there something one can do about this? The problem is that ['a. (< m : t; .. > as 'a)] is interpreted in a special way, 'a meaning the row variable rather than the whole type, and that does not work with constrained types. The workaround is to use a class-type: # class type t = object method output : (string -> unit) -> unit end;; class type t = object method output : (string -> unit) -> unit end # class a = object method f : 'a. (#t as 'a) -> unit = fun o -> o#output print_string end;; class a : object method f : #t -> unit end This does exactly what you want. Jacques Garrigue