On Sunday, January 26, 2014 5:59:03 PM UTC+1, John Myles White wrote:
>
> Right now this is a little tricky. It’s come up before and will probably
> have some kind of solution in the future.
>
> For now, you might find
> http://grollchristian.wordpress.com/2014/01/22/julia-inheriting-behavior/useful.
>
>
Thanks, that was an interesting read which addresses exactly what I was
doing. I have a related question, that maybe you (or someone else) can
answer. I have the following type:
type MotionVector <: AbstractArray{Float64}
v::Array{Float64}
MotionVector() = (x = new(); x.v = zeros(6, 1); x)
MotionVector(v) = (x = new(); x.v = v; x)
end
This seems to work, but when I do this, the display(MotionVector()) does
not work anymore, telling me:
ERROR: no method display(MotionVector)
in display at multimedia.jl:158
Without inheriting from AbstractArray{Float64}, this doesn't happen.
>
> — John
>
> On Jan 26, 2014, at 8:53 AM, Jesse van den Kieboom
> <[email protected]<javascript:>>
> wrote:
>
> > Hi all,
> >
> > I'm new to julia, so forgive me for maybe asking something obvious. What
> I would like to do is to create a new type which is basically an
> Array{Float64, 2}, but has some special operations defined as part of the
> vector space that it belongs to.
> >
> > What I currently do is to create a new composite type with one field
> containing the underlying array. This kind of works, but I need to proxy a
> lot of operators (*, -, +, etc) and methods (getindex, setindex!, convert,
> display, ndims, size), which do not need special behavior, to the
> underlying array.
> >
> > Initially, I tried to use a typealias instead of a composite type, but
> it seems the typealias type information is not retained and so I can't
> define new operations on it. Does anyone have a better way to implement
> this?
>
>