Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
mutually recursive classes (yes - again)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: briand@a...
Subject: mutually recursive classes (yes - again)

I've read the other threads on this common subject and I am not
getting understanding.

So I present the following very simple example with the hopes that
some kind person will help.

The definition is very simple making use of the "and" keyword 

class type a1 = 
  val a:a1
  val b:a2
and a2
  val c:a2
  val d:a1

It's the implementation which gives me trouble.  And yes there is an
example in the manual (3.15) and it just doesn't go quite far

now I have to define the clases

class a1 (x:a1) (y:a2) =
  val a = x
  val b = y

class a2 (x:a2) (y:a1) =
  val c = x
  val d = y

So now 

let z1 = new a1 ?? ?? ;;
let z2 = new a2 ?? ?? ;;

Obviously I need to "ground" the recursion somehow, but without some
sort of "Null" or "Void" value to use to instantiate the a1 field of
a1 it's not obvious to me how to do it.

I'm sure it will be embarassingly simple ...

I have about 7 more classes in this recursion-fest and a nice orderly
way to handle it would be VERY helpful.