caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* mutually recursive classes (yes - again)
@ 2005-01-10  3:49 briand
  2005-01-10  7:35 ` [Caml-list] " skaller
  0 siblings, 1 reply; 2+ messages in thread
From: briand @ 2005-01-10  3:49 UTC (permalink / raw)
  To: caml-list


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 = 
object
  val a:a1
  val b:a2
end
and a2
object
  val c:a2
  val d:a1
end
;;

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

now I have to define the clases

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

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

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.

TIA.

Brian


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] mutually recursive classes (yes - again)
  2005-01-10  3:49 mutually recursive classes (yes - again) briand
@ 2005-01-10  7:35 ` skaller
  0 siblings, 0 replies; 2+ messages in thread
From: skaller @ 2005-01-10  7:35 UTC (permalink / raw)
  To: briand; +Cc: caml-list

On Mon, 2005-01-10 at 14:49, briand@aracnet.com wrote:

> let z1 = new a1 ?? ?? ;;
> let z2 = new a2 ?? ?? ;;
> 
> Obviously I need to "ground" the recursion somehow,

Try

let rec 
  z1 = new a1 z1 z2 and
  z2 = new a2 z2 z1 
;;

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

Try 

class a1 (x:a1 option) (y:a2 option) =

a1 option has value

Some of a1 | None

and so is like a C pointer. 

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-01-10  7:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-10  3:49 mutually recursive classes (yes - again) briand
2005-01-10  7:35 ` [Caml-list] " 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).