English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [Caml-list] Mutually recursive classes
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-11-04 (17:50)
From: Damien <Damien.Pous@e...>
Subject: Re: [Caml-list] Mutually recursive classes
I could solve my problem by first defining two "open class type", and
then unifying 'self with the parameter in two other class types :

class type ['a, 'b] a_ot = object
	constraint 'b = ('a, 'b) #b_ot
	method	 coerce: 'a
	method	b: 'b
end and ['a, 'b] b_ot = object
	constraint 'a = ('a, 'b) #a_ot
	method	 coerce: 'b
	method	a: 'a

class type ['b] a_t = object ('s) inherit ['s, 'b] a_ot end
class type ['a] b_t = object ('s) inherit ['a, 's] b_ot end

It was the same kind of problem as the one discussed in

the parameters of a class are generalized after its type has been
thus, with

class type ['b] a = object ('sa)
  method coerce: 'sa
  method b: 'b
  constraint 'b = 'sa #b
end and ['a] b = object ('sb)
  method coerce: 'sb
  method a: 'a
  constraint 'a = 'sb #a

ocaml tries to unify 'sa (resp. 'sb) and 'a (resp. 'b) which is
impossible since this would close the self types

I lack some OO theory knowledges to understand the Jacques Garrigue's
distinction between "structural definition" and "definition by name"
(could someone explain me or send me some useful links ?)

but I think that recursion with distinct type parameters should be
allowed in the case above (recursive class _types_),
disallowing it seems to me like a boring syntactic restriction, since
one can always :
 - duplicate and separate the class type definitions ; (a_ot, b_ot)
 - add parameters for forward type definitions ('a, 'b)
 - glue all these types together to find back the first ones (a_t, b_t)

Does anyone know a case where this is not true ? (with class types)
What kind of "fully-recursive" classes are meaningless (just curious)


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