CanonicalTraits.jl icon indicating copy to clipboard operation
CanonicalTraits.jl copied to clipboard

default methods failed for Julia 1.0 and 1.1

Open thautwarm opened this issue 6 years ago • 1 comments

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

thautwarm avatar Sep 12 '19 17:09 thautwarm

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

thautwarm avatar Sep 12 '19 17:09 thautwarm