In ODE.jl, I would like to be able to take the norm of a Vector
containing other things than just numbers:
type Point
x::Float64
y::Float64
end
Base.norm(pt::Point, p=2) = norm([pt.x, pt.y], p)
norm(Point(3,4)) # == 5
norm([Point(3,4), Point(3,1)]) # does not work:
# ERROR: `abs` has no method matching abs(::Point)
# in generic_vecnormInf at linalg/generic.jl:70
# in generic_vecnorm2 at linalg/generic.jl:92
# in vecnorm at linalg/generic.jl:146
# in norm at linalg/generic.jl:156
Of course defining
Base.abs(pt::Point) = norm(pt)
makes it work, however, it's not that nice as abs is reserved for
numbers. Does that mean that I also need to define my own norm for each
Vector{...} where ... is my compound type or is there a more general
approach? Would it not make sense to use `norm` instead of `abs` inside
vecnorm, as abs==norm for numbers? (If so, what should p be for the
inside norms?)
References:
https://github.com/JuliaLang/julia/pull/6057
https://groups.google.com/forum/#!msg/julia-users/RJO-JCVV7rg/4qHjMbPd9YAJ