# Capturing a parameter of a type!

**URL:** <https://discourse.julialang.org/t/capturing-a-parameter-of-a-type/30842>\
**Category:** General Usage\
**Created:** [November 7, 2019, 7:02pm UTC](https://discourse.julialang.org/t/capturing-a-parameter-of-a-type/30842 "2019-11-07T19:02:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 7, 2019, 7:02pm UTC](https://discourse.julialang.org/t/capturing-a-parameter-of-a-type/30842/1 "2019-11-07T19:02:13Z")

</div>

```julia
abstract type MM{T} end

capture(::Type{MM{T}}) where T = T

capture(MM{Int})
Int64

julia> const CMM{C} = MM{T} where T<:C
MM{T} where T<:C where C

julia> capture(::Type{CMM{T}}) where T = T
capture (generic function with 2 methods)

julia> capture(CMM{Int})
ERROR: UndefVarError: T not defined
Stacktrace:
 [1] capture(::Type{MM{T} where T<:Int64}) at ./REPL[5]:1
 [2] top-level scope at REPL[6]:1

```

The second one doesn’t work? Is there a way to capture Int in the second example?

Thanks

---

<div class="post-metadata">

**Author:** ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)\
**Post date:** [November 7, 2019, 11:29pm UTC](https://discourse.julialang.org/t/capturing-a-parameter-of-a-type/30842/3 "2019-11-07T23:29:14Z")

</div>

To me the error makes sense. Note that the problem is not in “capturing” the type, but rather the definition of `CMM`: in

```julia
const CMM{C} = MM{T} where T<:C

```

what type is `T` supposed to be?

---

<div class="post-metadata">

**Author:** ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)\
**Post date:** [November 8, 2019, 12:32am UTC](https://discourse.julialang.org/t/capturing-a-parameter-of-a-type/30842/4 "2019-11-08T00:32:36Z")

</div>

I think an interesting aspect is that this still happens when `C` is `Int` which is a concrete type. Shouldn’t upper-bounding by a concrete type determine the type parameter? The reason that it’s not enough is `Union{} <: Int`. Because of this, we have:

```julia
julia> abstract type MM{T} end

julia> CMM{C} = MM{T} where T<:C
MM{T} where T<:C where C

julia> MM{Int} <: CMM{Int}
true

julia> MM{Union{}} <: CMM{Int}
true

```

So, `julia` can’t decide what `T` in `MM{T} where T<:C` should be.

This just caused an “interesting” bug in StaticArrays: [https://github.com/JuliaArrays/StaticArrays.jl/pull/685](https://github.com/JuliaArrays/StaticArrays.jl/pull/685). See also:

[https://github.com/JuliaLang/julia/issues/33780](https://github.com/JuliaLang/julia/issues/33780)
