* Classes/objects with internal references to lists of objects of the same type
@ 2010-02-05 19:16 Tim Hanson
2010-02-05 21:04 ` [Caml-list] " Andreas Rossberg
0 siblings, 1 reply; 2+ messages in thread
From: Tim Hanson @ 2010-02-05 19:16 UTC (permalink / raw)
To: OCaml List
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Classes/objects with internal references to lists of objects of the same type
2010-02-05 19:16 Classes/objects with internal references to lists of objects of the same type Tim Hanson
@ 2010-02-05 21:04 ` Andreas Rossberg
0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rossberg @ 2010-02-05 21:04 UTC (permalink / raw)
To: Tim Hanson; +Cc: OCaml List
[-- Attachment #1: Type: text/plain, Size: 586 bytes --]
On Feb 5, 2010, at 20.16 h, Tim Hanson wrote:
>
> 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
> -------
Try:
class a_pad =
object
val mutable parent_mod = new a_mod
val mutable connected : a_pad list = []
end
and a_mod =
object
val mutable pads : a_pad list = []
end
Cheers,
/Andreas
[-- Attachment #2: Type: text/html, Size: 1281 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-02-05 21:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-05 19:16 Classes/objects with internal references to lists of objects of the same type Tim Hanson
2010-02-05 21:04 ` [Caml-list] " Andreas Rossberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox