Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M3/multitraits #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

M3/multitraits #2

wants to merge 6 commits into from

Conversation

mauro3
Copy link
Owner

@mauro3 mauro3 commented Sep 28, 2015

Edit: this would be cool but increases the code complexity considerably. It might be easier to provide this functionality with generated functions. So, if demand for this feature materializes, revisit.

I think I'll merge this after a bit of settling. This came out of discussions over in JuliaLang/julia#13222. This adds:

  • inheritance
  • trait functions dispatching on several traits (although only a fixed set)

This is a breaking change because now trait-functions need to be initialized via:
@traitfn f{X; TR{X}}(x::X)
(sans =...).

I think this is as far as Holy Traits can be taken. Going further would get into the Traits.jl territory of trait-dispatch and trait-definitions via method specifications.

@mauro3
Copy link
Owner Author

mauro3 commented Jul 25, 2016

Part of the addition looks like so (from the README):

Dispatch on several traits

It is also possible to dispatch on several traits:

@traitfn f55{X, Y;  TT1{X},  TT2{Y}}(x::X, y::Y)
@traitfn f55{X, Y;  TT1{X},  TT2{Y}}(x::X, y::Y) = 1
@traitfn f55{X, Y; !TT1{X},  TT2{Y}}(x::X, y::Y) = 2
@traitfn f55{X, Y;  TT1{X}, !TT2{Y}}(x::X, y::Y) = 3
@traitfn f55{X, Y; !TT1{X}, !TT2{Y}}(x::X, y::Y) = 4

Note that all methods need to feature the same traits (possibly
negated) in the same order. Any method violating that will never be
called (without an error being thrown).

@JeffreySarnoff
Copy link

This capability is very important to Traits being "trait-like" in the humanistic sense.
Any time I think of a trait-ified way, naturally, there are almost always simultaneous ontologically kinda-orthogonal multiple traits co-dispatching (and with a type or two).

@mauro3
Copy link
Owner Author

mauro3 commented Sep 15, 2016

Thanks @JeffreySarnoff, I take this as a +1 :-)

@vollmersj
Copy link

Any update here?

@mauro3
Copy link
Owner Author

mauro3 commented Jul 6, 2018

No. If you're at JuliaCon we could discuss it there.

@InterdisciplinaryPhysicsTeam

Hi,

Would you have any updates on this?

Thanks

@mauro3
Copy link
Owner Author

mauro3 commented Jun 11, 2022

I don't have any plans with this, nor time.

@MilesCranmer
Copy link

Friendly ping :)

I dream of rust-like generics in Julia; this PR would make it so!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants