I want to make a parametric type that needs some checking, so I want to
include an inner constructor. But since the type of the arguments can
change, then the method of checking (the validity of the arguments) needs
to depend on the type. I know the following works, but thought it would be
good to ask if this is bad practice in any way:
type A{T}
x::T
function A(y::Number)
y < 0 ? new(zero(y)) : new(y)
end
function A(y::Char)
y == 'a' ? new('b') : new(y)
end
end
A{T}(x::T) = A{T}(x)
In reality I'll have about four different types that A's argument can have
and therefore four different inner constructor methods...
Thanks!