It's because

julia> super(Bool)
Integer

julia> super(Integer)
Real

and you'd expect these to be defined for Integers. If this weren't the case 
then

function myalgorithm{T<:Real}(x::AbstractArray{T})
    # do something involving abs
end

would fail if the user supplied an array of Bools. I could create a special 
version of myalgorithm for Array{Bool} that omitted calls to abs, but that 
would be a pain in the neck, and I'd have to worry about every single possible 
element type ("does Uint16 have an abs method? let's check"). Since Julia 
compiles a new version of myalgorithm specificially for Array{Bool}, there's 
also no performance hit (such trivial functions just get inlined out into no-
ops).

--Tim

On Wednesday, September 10, 2014 10:20:42 PM Dan Luu wrote:
> In bool.jl, there are things like
> 
> signbit(x::Bool) = false
> sign(x::Bool) = x
> abs(x::Bool) = x
> abs2(x::Bool) = x
> 
> Are these because Bool is a subtype of something where you'd expect
> these to be defined, or are these useful in their own right, and if
> so, when would you use these?
> 
> 
> Thanks,
> Dan

Reply via email to