-
Notifications
You must be signed in to change notification settings - Fork 6
abstract types as traits #1
Comments
cc @abeschneider (who previously did type traits... perhaps that could be re-written using Traits.jl ? also see @jiahao's post https://groups.google.com/forum/#!topic/julia-dev/iBBSQt1FGHE |
Both abstract and concrete types are a bit like traits as they impliclty have an interface defined by the generic functions which apply to them. Concrete types, however, are also about storing data. At the moment this would be a Traits replacement for @traitdef TNumber{N} begin
@constraints begin
N==Number
end
end But I have no idea whether traits should replace abstract types. And it would proably be hard as much of Julia is based on the current type system. And if so, a smart transition scheme should be put in place, which is what you're suggesting above. |
It kind of feels like your awesome Group example is a way in for abstract base classes (e.g. they must have certain attributes). I don't quite follow the TNumber example above as it still references Number. Will think on this a bit more as I understand Traits a bit better! Would be interesting to see if there is something here (as a concept), even thinking about being in base is way off IMO. The idea would be it's traits all the way down... |
Yes, the TNumber example is a bit ciruclar... It should work the same though if instead you include all the interface functions of Number into the trait-defintion. And then continue on do the same for all the subtypes (sticking to single trait-inheritance) should lead to something fairly equvalent to what Julia has now, at least in principle. |
Here some ideas on this https://github.com/mauro3/Traits.jl/blob/master/dev_notes.md#merging-implicit-interfaces-specified-on-types-with-traits. Although it's pretty rough, so you might not be able to make sense of it. |
I'm just throwing this out here from discussion in JuliaLang/julia#6975 (comment) (@skariel).
Could a trait perform the roles of abstract types (giving the user the simplicity/familiarity of abstract inheritance whilst actually providing a trait), so we would write something like:
(or maybe you'd just reuse
@traidef
.)I think that abstract types are in some sense an example of traits, but please forgive my ignorance. (There's also the issue of defining functions
function f(x::Number) ... end
... and probably more...)The text was updated successfully, but these errors were encountered: