Multiple-dispatch depending on output type?

This is exactly what was suggested. Typically in julia you will not use a construction like,

function sqrt(type, value)
    if type <: GAlgebra
        ...
    else
        ...
    end
end

rather you will make a

function sqrt(::Type{GAlgebra}, value)
    ...
end

Even though in the first case the if-test may be eliminated by constant folding/propagation, the second case is cleaner. The if-test is gone, it’s taken care of directly by the compile-time dispatch.

1 Like

Right, thank you for that explanation - it’s now clear to me what was meant by this

function sqrt(::Type{GAlgebra}, value)
    ...
end