* [Caml-list] Polymorphic class recursion (?)
@ 2003-09-18 16:19 Lukasz Stafiniak
2003-09-24 3:38 ` Jacques Garrigue
0 siblings, 1 reply; 2+ messages in thread
From: Lukasz Stafiniak @ 2003-09-18 16:19 UTC (permalink / raw)
To: caml-list
Hi,
# class c1 = object val v1 : unit #c2 option = None val v2 : bool #c2 option
= None end and ['a] c2 = object val v1 : #c1 option = None end;;
Characters 59-67:
class c1 = object val v1 : unit #c2 option = None val v2 : bool #c2 option
= None end and ['a] c2 = object val v1 : #c1 option = None end;;
^^^^^^^^
This type unit should be an instance of type bool
Why? This works for records. (Switching to class types (class --> class
type, without = parts) doesn't help.)
Thanks in advance,
Best Regards,
Lukasz
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Polymorphic class recursion (?)
2003-09-18 16:19 [Caml-list] Polymorphic class recursion (?) Lukasz Stafiniak
@ 2003-09-24 3:38 ` Jacques Garrigue
0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2003-09-24 3:38 UTC (permalink / raw)
To: luk_stafi; +Cc: caml-list
From: "Lukasz Stafiniak" <luk_stafi@wp.pl>
> # class c1 = object val v1 : unit #c2 option = None val v2 : bool #c2 option
> = None end and ['a] c2 = object val v1 : #c1 option = None end;;
> Characters 59-67:
> class c1 = object val v1 : unit #c2 option = None val v2 : bool #c2 option
> = None end and ['a] c2 = object val v1 : #c1 option = None end;;
> ^^^^^^^^
> This type unit should be an instance of type bool
>
> Why? This works for records. (Switching to class types (class --> class
> type, without = parts) doesn't help.)
The difference is that records types have an identity, while object
types are equal modulo structure.
What this means is that record and sum types may freely use
polymorphic recursion, but object and polymorphic variant types are
limited to regular recursion, as they are expanded to a regular tree
during unification (to check equality).
What this means in practice is there is no simple way to have
polymorphically recursive types: you must necessarily introduce either
a record or a sum type in the recursion.
Even if you do that, the next problem is that you cannot use your own
constructor polymorphically, since this would mean polymorphic
recursion at the expression level. There are two workarounds for that:
use a mutable polymorphic record field, or use the new recursive
modules in ocaml 3.07.
Anyway, that's really hard.
Sorry for the inconvenience, but this kind of polymorphic methods is
easier to define outside of the class.
Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-09-24 3:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-18 16:19 [Caml-list] Polymorphic class recursion (?) Lukasz Stafiniak
2003-09-24 3:38 ` Jacques Garrigue
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).