[julia-users] Re: Avoiding duplicate code when defining concrete subtypes of an abstract type

2016-08-24 Thread Jeffrey Sarnoff
You may be stepping twice where once does nicely. `abstract Currency` establishes Currency as an abstract type [in Julia, by convention, type names are capitalized; it helps others to stay with that practice]. If we want to use it `abstract Cash <: Currency` establishes Cash as sub-abstractio

[julia-users] Re: Avoiding duplicate code when defining concrete subtypes of an abstract type

2016-08-25 Thread Ralph Smith
If you don't need the flexible interrelations provided by J. Sarnoff's approach, you might use metaprogramming like this: abstract Cash function _validate(p::Cash) p.b >= 100 && throw(ArgumentError("Too much...")) (p.b < 0 || p.a < 0) && throw(ArgumentError("Cannot have negative amount