tk3369 / BinaryTraits.jl

Can do or not? It's easy. See https://tk3369.github.io/BinaryTraits.jl/dev/
MIT License
53 stars 3 forks source link

RFC: allow to assign parameterized types with traits #35

Closed KlausC closed 4 years ago

KlausC commented 4 years ago

It would be cool, if I could do:

@trait Sparse prefix Is,Not
@assign Adjoint{T,SparseVector{T}} where T with Sparse

Currently I have to use this work-around, because the @assign macro expects a Symbol as a first argument.

julia> @trait Sparse prefix Is,Not

julia> const AVS = Adjoint{<:Any, SparseVector}
Adjoint{var"#s54",SparseVector} where var"#s54"

julia> @assign AVS with Sparse
julia> @implement IsSparse by nnz()
julia> nnz(a::Adjoint{<:Any, SparseVector}) = nnz(a.data)
nnz (generic function with 2 methods)

julia> check(Adjoint{Float64, SparseVector})
✅ Adjoint{Float64,SparseVector} has implemented:
1. SparseTrait: IsSparse ⇢ nnz(::<Type>)::Any
tk3369 commented 4 years ago

In the back of my mind, it doesn't seem too bad to make users define meaningful names for specific parametric types as I generally find the code more readable that way. I do not oppose to supporting this though.

KlausC commented 4 years ago

I close this, because after #38 the issue is resolved.