You could also just write it using outer constructors. It is slightly more verbose, but cleans up the A type nicely.
type A{T} x::T end function A{T<:Number}(y::T) y < 0 ? A{T}(zero(y)) : A{T}(y) end function A(y::Char) y == 'a' ? A{Char}('b') : A{Char}(y) end julia> A('a') A{Char}('b') julia> A('C') A{Char}('C') julia> A(-100) A{Int64}(0) julia> A(10.4) A{Float64}(10.4) Cheers, Kevin On Fri, May 8, 2015 at 1:51 AM, Toivo Henningsson <toivo....@gmail.com> wrote: > I think this is fine. You could also have a helper function that does the > checking and is called by the inner constructor. If you define it inside > the type it will only be accessible to the inner constructor (and other > functions within the type).