Perhaps you could include the function amongst the elements of the type? immutable MyArray array::Array fill::Function
MyArray(array)=new(array,i->fill!(array,i)) end B=MyArray(zeros(5,2)); B.array 5x2 Array{Float64,2}: 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 B.fill(1); B.array 5x2 Array{Float64,2}: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 Does that help? Note that I have no idea how well it would perform in terms of optimisation. On Thursday, 8 October 2015 01:13:33 UTC+10, cheng wang wrote: > > Hello everyone, > > In some cases, I would like to make a function belongs to an object. > In classical OO, we do something like object.f(args...). > In Julia, we could do it like this: f(object, args...). > > So I was wandering if there is some way to do following: > I write object.f(args...), while julia could know it actual means > f(object, args...). > > One naive way to implement this is in two steps: > first, the compiler search for a field of object equal to f, if it's not > found, > then, compiler search for a function like f, and the invoke it. > > Looking forward for your opinions! >