obj::Array{SelfRef,0} # The 2nd parameter to Array is the dimension, so
you're declaring obj to be a zero-dimensional array; you probably want
obj::Array{SelfRef,1}
Similarly with:
x.obj =Array(x,0)
the 1st argument to Array is the *type* of Array you want to create, so
this should be
x.obj=Array(SelfRef,0)
which will create an empty SelfRef[] Array.
Hope that helps!
-Jacob
On Wed, Jun 18, 2014 at 4:32 AM, Luke Stagner <[email protected]> wrote:
> Hello all,
>
> I know it is possible to have a self-referential type like the following
>
> type SelfRef
> obj::SelfRef
> SelfRef() = (x=new(); x.obj=x)
> end
>
> what I want to do is have obj be an array of type SelfRef so I can make a
> tree-like structure. I tried the following
>
> type SelfRef
> obj::Array{SelfRef,0}
> SelfRef() = (x=new(); x.obj=Array(x,0))
> end
>
> but that throws the following error (on nightly)
> julia> a=SelfRef()
> ERROR: no method Array{T,N}(SelfRef)
> in SelfRef at none:3
>
> Is there anyway I can make this work?
>