mauro3 / SimpleTraits.jl

Simple Traits for Julia
MIT License
159 stars 14 forks source link

Convert traitfns to use where-syntax #46

Closed mauro3 closed 6 years ago

mauro3 commented 7 years ago

Yep, but needs to wait for https://github.com/JuliaLang/julia/issues/23211

mauro3 commented 7 years ago

JuliaLang/julia#23211 is a won't fix, but only affects Julia 0.6. So, either this needs to wait for 0.7 or the syntax needs to be changed. A possibility is:

@traitfn f{X; Tr{X}}(x::X) = 1
# would be
@traitfn f(x::X) where trait(Tr{X})<:Tr{X} where {X} = 1

# Multitrait
@traitfn f(x::X, y::Y) where trait(Tr2{X,Y})<:Tr2{X,Y} where {X,Y} = 1

or using the syntax overhauls proposed in #45

@traitfn f(x::X) where Tr(X)<:Tr where {X} = 1

# Multitrait
@traitfn f(x::X, y::Y) where Tr2(X,Y)<:Tr2 where {X,Y} = 1

The nice thing about this is that it clearly states that a computation on the types, e.g. Tr2(X,Y) is done, and that the result of that is then compared to some type. X-ref: https://discourse.julialang.org/t/why-does-julia-not-support-multiple-traits/5278/25, https://github.com/JuliaLang/julia/pull/18457#issuecomment-261755320

sbromberger commented 6 years ago

@mauro3 - would it be possible to tag a 0.7-only version of SimpleTraits so we can start migrating LightGraphs using the new where syntax?

mauro3 commented 6 years ago

Yes, but I would rather wait for feature freeze to happen before spending time chasing 0.7.

sbromberger commented 6 years ago

Makes sense to me :) Thanks.

(Though didn't feature freeze happen on December 15?)

mauro3 commented 6 years ago

No, it didn't quite yet, but should soon: https://discourse.julialang.org/t/1-0-feature-freeze-dec-15th/7209/28

sbromberger commented 6 years ago

https://discourse.julialang.org/t/1-0-feature-freeze-dec-15th/7209/34 - any way we might be able to start soon?

mauro3 commented 6 years ago

I haven't forgotten this but I have not found the time yet. Sorry! Hopefully the week after next.

mauro3 commented 6 years ago

@sbromberger (or @rohitvarkey ): I fixed the where-syntax issue in #51. Maybe you can give that branch a spin?

sbromberger commented 6 years ago

@mauro3 working on it now. Hopefully will have results soon.

sbromberger commented 6 years ago

@mauro3 things seem to be working very well with this branch. Thank you.

sbromberger commented 6 years ago

@mauro3 - any chance you could tag this? We're moving ahead with https://github.com/JuliaGraphs/LightGraphs.jl/pull/848 since there are a large number of deprecations we need to fix prior to 0.7. Being able to reference it it REQUIRES would be awesome.

mauro3 commented 6 years ago

Tagged: https://github.com/JuliaLang/METADATA.jl/pull/13453

sbromberger commented 6 years ago

Perfect. Thank you :)