* Polymorphic variants in class methods
@ 2000-10-08 22:18 malc
2000-10-11 2:35 ` Jacques Garrigue
2000-10-11 18:54 ` Brian Rogoff
0 siblings, 2 replies; 3+ messages in thread
From: malc @ 2000-10-08 22:18 UTC (permalink / raw)
To: caml-list
# class foo = object method moo = `Bar end;;
Some type variables are unbound in this type:
class foo : object method moo : [> `Bar] end
The method moo has type [> `Bar] where 'a is unbound
Someone care to comment on that?
P.S. Uhm, like im totaly lost on whats going on here.
--
mailto:malc@pulsesoft.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Polymorphic variants in class methods
2000-10-08 22:18 Polymorphic variants in class methods malc
@ 2000-10-11 2:35 ` Jacques Garrigue
2000-10-11 18:54 ` Brian Rogoff
1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2000-10-11 2:35 UTC (permalink / raw)
To: malc; +Cc: caml-list
From: malc <malc@pulsesoft.com>
> # class foo = object method moo = `Bar end;;
> Some type variables are unbound in this type:
> class foo : object method moo : [> `Bar] end
> The method moo has type [> `Bar] where 'a is unbound
You can see it as a bug in the error message printer: the real message
should be
The method moo has type ([> `Bar] as 'a) where 'a is unbound
That is, the type [> `Bar] is not fully specified (it contains a row
variable), and as a result you cannot use it in a method type, which
must be fully specified.
Easy solution, add a type annotation:
# class foo = object method moo : [`Bar] = `Bar end;;
class foo : object method moo : [ `Bar] end
Jacques
---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Polymorphic variants in class methods
2000-10-08 22:18 Polymorphic variants in class methods malc
2000-10-11 2:35 ` Jacques Garrigue
@ 2000-10-11 18:54 ` Brian Rogoff
1 sibling, 0 replies; 3+ messages in thread
From: Brian Rogoff @ 2000-10-11 18:54 UTC (permalink / raw)
To: malc; +Cc: caml-list
On Mon, 9 Oct 2000, malc wrote:
> # class foo = object method moo = `Bar end;;
> Some type variables are unbound in this type:
> class foo : object method moo : [> `Bar] end
> The method moo has type [> `Bar] where 'a is unbound
>
> Someone care to comment on that?
As Jacques Garrigue has pointed out, typing of polymorphic variants is
subtle, and the interaction of polymorphic variant and object typing is
very subtle. Let me try and explain simply and an expert can tell if I am
wrong or inaccurate...
Types described by "[>" are polymorphic and can be extended with new
tags, so they have an implicit type variable.
OCaml classes can be polymorphic, but methods must be monomorphic, so
your example is similar to
# class foo = object method moo = List.length end;;
Some type variables are unbound in this type:
class foo : object method moo : 'a list -> int end
The method moo has type 'a list -> int where 'a is unbound
Now, an oft discussed extension to OCaml is polymorphic methods (and an
even more oft discussed extension would allow polymorphic recursion in
the core (non OO) language) which would have you explicitly provide
the type for that method. This was supported in OLabl. I don't know the
OLabl incantation to type your program, but for the example I gave I
think it is
class foo = object method moo : 'a . 'a list -> int = List.length end;;
One way to make your program typecheck is to define the set of variants
you want to deal with, like so.
# type t = [`Foo | `Bar | `Baz];;
type t = [ `Foo | `Bar | `Baz]
# class foo = object method moo : t = `Bar end;;
class foo : object method moo : t end
> P.S. Uhm, like im totaly lost on whats going on here.
Ummm, like I totally hope this helps, dude. :-)
I think you'll want to at least read "Programming with Polymorphic
Variants" which you can download from
http://wwwfun.kurims.kyoto-u.ac.jp/soft/olabl/
-- Brian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2000-10-11 19:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-10-08 22:18 Polymorphic variants in class methods malc
2000-10-11 2:35 ` Jacques Garrigue
2000-10-11 18:54 ` Brian Rogoff
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox