Version française
Home     About     Download     Resources     Contact us    
Browse thread
Classes/objects with internal references to lists of objects of the same type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Tim Hanson <sideskate@g...>
Subject: Classes/objects with internal references to lists of objects of the same type
Hi All,

I'm trying to make two classes that have internal references to
themselves and each other, but can't figure it out. e.g:
-------
class a_pad = object
	val mutable parent_mod = new a_mod
	val mutable connnected : 'a_pad list = []
end

class a_mod = object
	val mutable pads : 'a_pad list = []
end
-------
The a_pad objects need to call routines in their parent module, and
most importantly, they need to know what other pads they are connected
to.

I understand that this is possible with stuff like:
-------
type expr = Mod of float * float * float * expr list
| Pad of float * float * float * expr * expr list
-------
But that's quite cumbersome.  The imperative programming style is
useful here, since all the contained float data needs to change
constantly.  (the tree structure does not).

thank you in advance for your help.
Tim