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

Parametric types with traits #81

Closed
gdalle opened this issue Mar 14, 2022 · 1 comment
Closed

Parametric types with traits #81

gdalle opened this issue Mar 14, 2022 · 1 comment

Comments

@gdalle
Copy link

gdalle commented Mar 14, 2022

Is it possible to define parametric types with SimpleTraits.jl?
The package documentation shows examples like

@traitfn f(x::X) where {X; IsNice{X}} = "Very nice!"
@traitfn f(x::X) where {X; !IsNice{X}} = "Not so nice!"

but I have yet to see the same for parametric types. What I'm looking for is something like

@traitstruct MyType{X} where {X; IsNice{X}} end

Does this syntax exist somewhere?

@mauro3
Copy link
Owner

mauro3 commented Mar 14, 2022

No, SimpleTraits has no such feature. I think you should be able to hand code it. I think what you are after is called an "associated type" at least in the Rust community. I did some work on that back in the Traits.jl days, maybe looking through that repo could be of help https://github.com/mauro3/Traits.jl.

I will close this as I do not plan to implement such a feature. Feel free to ask more question here though.

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

No branches or pull requests

2 participants