CanonicalTraits.jl
CanonicalTraits.jl copied to clipboard
default methods failed for Julia 1.0 and 1.1
caused by https://github.com/JuliaLang/julia/issues/33240 causing https://github.com/thautwarm/GeneralizedGenerated.jl/issues/17
@trait Typeable{T} begin
to_type :: T => Type{<:TypeLevel{T}}
to_type(x::T) = TVal{T, x}
from_type :: Type{<:TypeLevel{T}} => T
from_type(t::Type{<:TypeLevel{T}}) = interpret(t)
show_repr :: [IO, Type{<:TypeLevel{T}}] => Nothing
show_repr(io, t) = begin
print(io, from_type(t))
end
end
solution: For default methods, don't write type parameters in annotations.
You can still use type parameters like T inside the function body.
@trait Typeable{T} begin
to_type :: T => Type{<:TypeLevel{T}}
to_type(x) = TVal{T, x}
from_type :: Type{<:TypeLevel{T}} => T
from_type(t) = interpret(t)
show_repr :: [IO, Type{<:TypeLevel{T}}] => Nothing
show_repr(io, t) = begin
print(io, from_type(t))
end
end