From the README on SimpleTraits.jl
it appears dispatching on multiple traits is not yet possible.
However WhereTraits.jl
could possibly support it!
using WhereTraits
abstract type AbstractA end
abstract type DecoA <: AbstractA end
# A few concrete types
struct A <: AbstractA end
struct A1 <: DecoA end
struct A2 <: DecoA end
struct A3 <: DecoA end
# just some function
f(::AbstractA, x) = x+2
g(::DecoA, x, y) = x+y
is_nice(::Type{<:A1}) = true
is_nice(::Type{<:DecoA}) = false
is_cool(::Type{<:A2}) = true
is_cool(::Type{<:DecoA}) = false
@traits f(a::TA, x) where {TA <: DecoA, is_nice(TA)} = g(a,x,3)
@traits f(a::TA, x) where {TA <: DecoA, is_cool(TA)} = g(a,x,5)
@traits f(a::TA, x) where {TA <: DecoA, !is_cool(TA), !is_nice(TA)} = "without this the multiple dispatch is ill-defined for `A3`"
@show f(A(),0)
@show f(A1(),0)
@show f(A2(),0)
@show f(A3(),0)