Hi,
I'm a new scientific user and Julia is an exciting prospect. I read through
the manual on types and methods, but got confused about how I can define a
new abstract type (= trait according to some of the literature)
abstract AbsType
and write methods for it such as
function func2(x::AbsType)
func1(x) + func1(x)
end
I can trust that whatever object that has been passed being of a concrete
type
ConcType <: AbsType
attr::Number
end
should always come with the completely necessary method func1(x::ConcType)?
When I tried this (run all the codeblocks above) without defining func1, I
got no failures until I called func2(foo) where foo=ConcType(25813).
If I instead defined a "fallback" method
function func1(x::AbsType)
0
end
then calling func2(foo) merrily returns 0 instead of 51626. This is either
a nice feature or a silent failure depending on the intentions of whoever
(not myself) decided not to or forgot to implement func2(ConcType).
I'm aware that 1) obviously there wasn't anywhere else before then that was
particularly reasonable for the interpreter to fail during my trial, and 2)
classes and inheritance are declasse. Then in Julia's type system (as
implemented now or planned in the near future), what's the best guarantee I
can give myself as I write a module that defines AbsType and func2 beyond
writing great docs and hoping that the people who implement their own
ConcType will read the docs as well as write unit tests for their new type?
Many Thanks,
Menyoung