# Using parametric type inside outer parametric constructor

**URL:** <https://discourse.julialang.org/t/using-parametric-type-inside-outer-parametric-constructor/53388>\
**Category:** General Usage\
**Tags:** linearalgebra, parametric-types, potential-bug\
**Created:** [January 15, 2021, 3:37pm UTC](https://discourse.julialang.org/t/using-parametric-type-inside-outer-parametric-constructor/53388 "2021-01-15T15:37:33Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [January 15, 2021, 5:08pm UTC](https://discourse.julialang.org/t/using-parametric-type-inside-outer-parametric-constructor/53388/6 "2021-01-15T17:08:44Z")

</div>

Removing the `<:` from the type definition makes it work:

This works:

```julia
julia> struct Foo{T<:Real, S<:AbstractMatrix{T}}
               data::S
               n::Int
       end

julia> Foo(A::AbstractMatrix{T}, n::Int) where {T<:Real} = Foo{T, typeof(A)}(A, n)
Foo

julia> Foo{T}(::UndefInitializer,n) where {T<:Real} = Foo(Matrix{T}(undef,n,n),n)

julia> Foo{Float64}(undef,2)
Foo{Float64,Array{Float64,2}}([0.0 0.0; 0.0 0.0], 2)

julia>

```

This does not:

```julia
julia> struct Foo{T<:Real, S<:AbstractMatrix{<:T}} # the difference is the <: here
               data::S
               n::Int
       end

julia> Foo(A::AbstractMatrix{T}, n::Int) where {T<:Real} = Foo{T, typeof(A)}(A, n)
Foo

julia> Foo{T}(::UndefInitializer,n) where {T<:Real} = Foo(Matrix{T}(undef,n,n),n)

julia> Foo{Float64}(undef,2)
ERROR: UndefVarError: T not defined

```

Minimal example:

```julia
julia> struct Foo{T,S <: Vector{<:T}}
         x :: S
       end

julia> Foo{T}(::UndefInitializer) where T = Foo(Vector{T}(undef,2))

julia> Foo{Float64}(undef)
ERROR: UndefVarError: T not defined

```

---

_[View the full topic](https://discourse.julialang.org/t/using-parametric-type-inside-outer-parametric-constructor/53388)._
