# Inheriting from a Type Parameter

**URL:** https://discourse.julialang.org/t/inheriting-from-a-type-parameter/59010
**Category:** New to Julia
**Tags:** inheritance
**Created:** [April 10, 2021, 8:51pm UTC](https://discourse.julialang.org/t/inheriting-from-a-type-parameter/59010 "2021-04-10T20:51:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gphlipot](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@gphlipot](https://discourse.julialang.org/u/gphlipot)
#### Post date: [April 10, 2021, 8:51pm UTC](https://discourse.julialang.org/t/inheriting-from-a-type-parameter/59010/1 "2021-04-10T20:51:50Z")

</div>

I’m curious why Julia doesn’t let you define a parametric type that inherits from a parameter, e.g.

```julia
struct SomeType{T} <: T end

```

When I try this, Julia gives the error `invalid subtyping in definition of SomeType`.

It seems like this feature could be useful to systematically define types that behave like a `T`, but have a different implementation. For example, [StructArrays.jl](https://juliaarrays.github.io/StructArrays.jl/dev/) has the [Lazy Iteration](https://juliaarrays.github.io/StructArrays.jl/dev/#Lazy-iteration) feature where it can create a `LazyRow{T}` that sort of behaves like a `T` (by having `getproperty` behave the same for a `T` and a `LazyRow{T}`). However, since `LazyRow{T}` cannot inherit from `T` (or in the case that `T` is a concrete type, inherit from `supertype(T)`), you can’t use a `LazyRow{T}` as an argument for a function that expects a `T` (or a `supertype(T)`).

E.g. I would like have something like:

```julia
abstract type AbstractFoo end
struct Foo 
    # some representation of a Foo
end

# some function that is specialized for AbstractFoo
bar(foo::AbstractFoo) = 0

# create a StructArray of Foos to get a different representation of a Vector{Foo}
using StructArrays
foos = StructArray(Foo() for i in 1:100)

# lazy representation of a Foo
lazy_foo = LazyRow(foos,1)

# I would like to be able to do this, but it doesn't work
bar(lazy_foo)

```

But since `LazyRow{Foo}` cannot automatically inherit from `AbstractFoo`, this can’t be done.

---

<div class="post-metadata">

### Author: ![FPGro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fpgro/32/20822_2.png) [@FPGro](https://discourse.julialang.org/u/FPGro)
#### Post date: [April 10, 2021, 9:38pm UTC](https://discourse.julialang.org/t/inheriting-from-a-type-parameter/59010/2 "2021-04-10T21:38:41Z")

</div>

Hi, welcome to the community! See here for a short discussion and the semi-official answer to that request:

> [@Parametrically customized subtypes](https://discourse.julialang.org/t/parametrically-customized-subtypes/58258):
>
> I think this is the same feature discussed recently by the Symbolics and Julia compiler teams. I would be interested to see what the experts have to say on this topic. For each of many external abstract types T , I want to make a new abstract subtype of T whose dispatch users control. For example, a const LazyInteger = Lazy{Integer} that’s a subtype of Integer but has custom lazy method implementations. I can implement this for certain types manually, but I don’t think it’s currently possible…
