I build a new vector type:
type MyType
x::Vector{Float64}
end
I want to extend lots of the standard methods, eg addition, subtraction, element-wise comparison, etc to my new type. Do I need to define a method definition for each of them, eg:
+(a::MyType, b::MyType) = a.x + b.x
-(a::MyType, b::MyType) = a.x - b.x
.<(a::MyType, b::MyType) = a.x .< b.x
or is there some syntactic short-cut I can use here?
Here's an example using Julia's Metaprogramming:
You can inherit from
AbstractArray
and define a very small interface to get all the basic array operations for free:Let's test this: