I want to implement a prototype based system in Scala. At the root of the type hierarchy is a ROOT node, which has a prototype that references itself.
The following code demonstrates what I'm trying to do:
class Node(val prototype: Node) {
private def this() = this(this)
}
object Node {
val ROOT = new Node
}
Unfortunately, this does not compile the error: "it can only be used in a class, object, or template."
The argument "this" for calling the main constructor is not accepted. This sounds reasonable since the object has not yet been created. However, since the prototype is immutable, I cannot set its value to null and determine it afterwards.
Any suggestions on how to do this correctly in Scala?
I am using Scala -2.8.0RC7.