mauro3 / SimpleTraits.jl

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

Parametric types with traits #81

Closed gdalle closed 2 years ago

gdalle commented 2 years ago

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 commented 2 years ago

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.