caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <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
Date: Thu, 06 Jan 2005 09:24:13 +0900 (JST)	[thread overview]
Message-ID: <20050106.092413.25912872.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20050105.191433.84857869.Christophe.Troestler@umh.ac.be>

From: Christophe TROESTLER <Christophe.Troestler@umh.ac.be>

> 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


  reply	other threads:[~2005-01-06  0:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-05 18:14 Christophe TROESTLER
2005-01-06  0:24 ` Jacques Garrigue [this message]
2005-01-06  1:56   ` [Caml-list] " Christophe TROESTLER

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050106.092413.25912872.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=Christophe.Troestler@umh.ac.be \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).