# Add type mixins to overcome subtype limitations

**URL:** <https://discourse.julialang.org/t/add-type-mixins-to-overcome-subtype-limitations/816>\
**Category:** Internals & Design\
**Created:** [December 8, 2016, 11:47pm UTC](https://discourse.julialang.org/t/add-type-mixins-to-overcome-subtype-limitations/816 "2016-12-08T23:47:46Z")\
**Posts on this page:** 1\
**Showing post:** 27

<div class="post-metadata">

**Author:** ![krcools](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krcools/32/10212_2.png) [@krcools](https://discourse.julialang.org/u/krcools)\
**Post date:** [April 24, 2017, 1:00pm UTC](https://discourse.julialang.org/t/add-type-mixins-to-overcome-subtype-limitations/816/27 "2017-04-24T13:00:53Z")

</div>

I appreciate the effort, but I don’t think (and many with me as evidenced by e.g. [this topic](https://discourse.julialang.org/t/inheritance-for-matrix-wrapper-type/3346)) this is a satisfactory solution. It is of linear complexity in the API size, as opposed to constant complexity for traditional structure based inheritance, and it does not solve the fragility issue (augmented or modified APIs are not automatically picked up).

Would the issue not be solved if for every composite type the compiler would generate an associated anonymous abstract parent type and that inheritance from a composite would imply inclusion of its field and inheritance from the implied anonymous abstract type?

So, if I write:

```julia
immutable Base
  x::Int
end

```

this would be lowered to

```julia
abstract AbstractBase
immutable Base <: AbstractBase
  x::Int
end

```

and when I write

```julia
immutable Derived <: Base
  y::Int
end

```

this is taken to mean

```julia
abstract AbstractDerived <: AbstractBase
immutable Derived <: AbstractDerived
  @includefieldsfrom Base
  y::Int
end

```

Then if a function

```julia
f(obj::Base) = @show obj.x

```

is lowered to

```julia
f(obj::AbstractBase) = @show obj.x

```

it will also match objects of type `Derived`.

I feel these issues stem from the fact that types can either signify data layout or dispatch behaviour and that most programming languages including Julia mix up the two.

---

_[View the full topic](https://discourse.julialang.org/t/add-type-mixins-to-overcome-subtype-limitations/816)._
