# Why doesn't this code work? Related to Tuples and Types

**URL:** <https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772>\
**Category:** General Usage\
**Created:** [July 25, 2019, 3:08am UTC](https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772 "2019-07-25T03:08:18Z")\
**Posts on this page:** 4\
**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:** [July 25, 2019, 3:08am UTC](https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772/1 "2019-07-25T03:08:18Z")

</div>

Here is an example:

```nohighlight
mm(::Type{Tuple{X,Y}}) where X where Y = Type[X,Y]
julia> mm(Tuple{Int,T} where T<:Float64)
ERROR: UndefVarError: Y not defined
Stacktrace:
 [1] mm(::Type{Tuple{Int64,T} where T<:Float64}) at ./none:1
 [2] top-level scope at none:0

```

You can also try it with Base.unwrap\_all, the result is same.

Thanks

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [July 25, 2019, 3:25am UTC](https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772/2 "2019-07-25T03:25:12Z")

</div>

You want

```julia
julia> (mm(::Type{Tuple{X,Y}}) where X where Y) = Type[X,Y]
mm (generic function with 1 method)

```

* * *

Nevermind, completely misread that.

---

<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:** [July 25, 2019, 3:26am UTC](https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772/3 "2019-07-25T03:26:26Z")

</div>

what do you mean? that is no different from above.  
It doesn’t work either.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [July 25, 2019, 6:03am UTC](https://discourse.julialang.org/t/why-doesnt-this-code-work-related-to-tuples-and-types/26772/4 "2019-07-25T06:03:54Z")

</div>

Note the following:

```julia
julia> mm(::Type{Tuple{X,Y}}) where X where Y = :outer
mm (generic function with 3 methods)

julia> mm(::Type{Tuple{X,Y} where Y}) where X = :inner
mm (generic function with 3 methods)

julia> mm(::Type{Tuple{X,Y} where Y <: Float64}) where X = :specific
mm (generic function with 3 methods)

julia> mm(Tuple{Int,String})
:outer

julia> mm(Tuple{Int,T} where T<:Float64)
:specific

julia> mm(Tuple{Int,T} where T)
:inner

julia> mm(Tuple{Int,Float64})
:specific

```

I usually try not to do this kind of acrobatics and use some other, more transparent/readable mechanism, eg traits.
