* The universal variable 'a would escape its scope
@ 2005-01-05 18:14 Christophe TROESTLER
2005-01-06 0:24 ` [Caml-list] " Jacques Garrigue
0 siblings, 1 reply; 3+ messages in thread
From: Christophe TROESTLER @ 2005-01-05 18:14 UTC (permalink / raw)
To: O'Caml Mailing List
Hi,
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
If I do something with ['a list] instead of ['a t] (or if ['a t] is
abstract), I got no problem. If [f] is a function instead of a
method, it works. (I do _not_ want to have to coerce the object
passed to [f].)
Is there something one can do about this?
Cheers,
ChriS
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] The universal variable 'a would escape its scope
2005-01-05 18:14 The universal variable 'a would escape its scope Christophe TROESTLER
@ 2005-01-06 0:24 ` Jacques Garrigue
2005-01-06 1:56 ` Christophe TROESTLER
0 siblings, 1 reply; 3+ messages in thread
From: Jacques Garrigue @ 2005-01-06 0:24 UTC (permalink / raw)
To: Christophe.Troestler; +Cc: caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] The universal variable 'a would escape its scope
2005-01-06 0:24 ` [Caml-list] " Jacques Garrigue
@ 2005-01-06 1:56 ` Christophe TROESTLER
0 siblings, 0 replies; 3+ messages in thread
From: Christophe TROESTLER @ 2005-01-06 1:56 UTC (permalink / raw)
To: caml-list
On Thu, 06 Jan 2005, Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> wrote:
>
> 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.
Thanks,
ChriS
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-01-06 1:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-05 18:14 The universal variable 'a would escape its scope Christophe TROESTLER
2005-01-06 0:24 ` [Caml-list] " Jacques Garrigue
2005-01-06 1:56 ` Christophe TROESTLER
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox