I don’t think the interface for numbers is formally and extensively documented (yet?), but there are a couple of threads here on discourse where this topic was discussed. You might find valuable information there:
I recently ran into an issue overriding zero for my own Number:
julia> immutable Infinity <: Number end
julia> Base.zero(::Infinity) = 0
julia> import Base: +
julia> +(::Infinity,::Int) = Infinity()
+ (generic function with 181 methods)
julia> reduce(+,[Infinity(),Infinity()])
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Infinity
This may have arisen from a call to the constructor Infinity(...),
since type constructors fall back to convert methods.
Stack…
The announcement for CSV.jl v0.7 includes this new capability:
Custom types can now be passed in the … types keyword …, fast parsing is supported for all Integer and AbstractFloat types; other custom types need to support zero(T) and parse(T, str) to be parsed correctly.
That a custom numeric type T support zero(T) is entirely reasonable and of great utility to clients and other users of that type. With T a natural (whole) number type, zero(T) would throw a DomainError; and imo that…
From what I see and off the top of my head, I’d say that apart from promotion rules, you’ll still be missing:
a unary minus operator
comparison operators
probably a zero
method
5 Likes