caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Mutually recursive classes
@ 2003-11-03 17:41 pous damien
  2003-11-04 17:52 ` Damien
  0 siblings, 1 reply; 5+ messages in thread
From: pous damien @ 2003-11-03 17:41 UTC (permalink / raw)
  To: caml-list

On 3 Nov 2003, Didier Remy wrote:

> It looks similar to the subject/observer pattern.  
> Check Section 5.3 of the OCaml manual as well as my 
> APPSEM course notes
  
It only looks similar...
  
I am working with class _types_ :
This hierarchy is included in a large project, and I need
_readable_ interfaces (as well as _writeable_ :-)

I can't write
"constraint 'a = <an enormous explicit object type as 'b that has
already been written half a dozen times as 'a..>"

Furthermore, my classes _are_ mutually recursive : when I retrieve a   
parent from its child, I want a "full-featured parent" (and vice-versa)
 
damien    
 

-------------------
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] 5+ messages in thread
* [Caml-list] Mutually recursive classes
@ 2003-11-03 10:48 Damien
  2003-11-03 13:53 ` Didier Remy
  2003-11-07  7:34 ` skaller
  0 siblings, 2 replies; 5+ messages in thread
From: Damien @ 2003-11-03 10:48 UTC (permalink / raw)
  To: caml-list

Hello,

I would like to create two mutually recursive classes,
parents (a) and children (b)

Furthermore, I'd like to define them incrementally
parents and children,
parents and children with hands
parents and children with hands and feet
...

let's have a try :

class type ['b] a0 = object ('a)
  method coerce: 'a
  method b: 'b
  constraint 'b = 'a #b0
  (* ... *)
end and ['a] b0 = object ('b)
  method coerce: 'b
  method a: 'a
  constraint 'a = 'b #a0
  (* ... *)
end

class type ['b] a1 = object ('a)
  inherit ['b] a0
  constraint 'b = 'a #b1
  (* ... *)
end and ['a] b1 = object ('b)
  inherit ['a] b0
  constraint 'a = 'b #a1
  (* ... *)
end

...


Unfortunately, this does not work :
>    constraint 'b = 'a #b0
>                    ^^
>This type < b : 'b; coerce : 'a; .. > as 'a should be an instance of
>type 'c 
>Self type cannot escape its class

which is odd from my mind, since the following code is well typed :

class type ['c] c = object
  method c: 'c
end
class type ['b] a = object ('a)
  method b: 'b
  constraint 'b = 'a #c
end


I can get something better, using two type parameters :

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

but then the "self type" is no longer correlated to 'a/'b  so that I
can't implement the method coerce, 
so, I need to "virtualize" it, and to implement it only at the end of
the class hierarchy, 
where I need to close it, saying 'a = 'self / 'b = 'self

I don't want this, because I'd like be able to use these classes at any
level (yes, a parent without feet does make sense...)


Does this case of "Self type cannot escape its class" restriction really
make sense ?

Do you know how to work-around this ?

thanks,
damien

-------------------
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] 5+ messages in thread

end of thread, other threads:[~2003-11-07  8:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-03 17:41 [Caml-list] Mutually recursive classes pous damien
2003-11-04 17:52 ` Damien
  -- strict thread matches above, loose matches on Subject: below --
2003-11-03 10:48 Damien
2003-11-03 13:53 ` Didier Remy
2003-11-07  7:34 ` skaller

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).