# Tuple type don't inherit as expected

**URL:** https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636
**Category:** General Usage
**Tags:** question
**Created:** [November 17, 2018, 9:29am UTC](https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636 "2018-11-17T09:29:49Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [November 17, 2018, 9:29am UTC](https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636/1 "2018-11-17T09:29:49Z")

</div>

just did some experimentations with Tuple types. Take the following example

```julia
d = Dict{Int, Int}
d_unionall = Type{T} where T <: Dict
u = Union{String, Int}
u_unionall = Type{T} where T>:String
isa(d, d_unionall) # true
isa(u, u_unionall) # true

```

then the respective Tuple combination of both does not work

```julia
isa((d, u), Tuple{d_unionall, u_unionall}) # false :-( 

```

EDIT: subtyping works like expected

```julia
Tuple{Type{d}, Type{u}} <: Tuple{d_unionall, u_unionall} # true :-)

```

anyone an idea what is going on here?

---

<div class="post-metadata">

### Author: ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)
#### Post date: [November 17, 2018, 12:30pm UTC](https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636/3 "2018-11-17T12:30:59Z")

</div>

```julia
julia> isa((Int,), Tuple{Type{Int}})
false
julia> isa.((Int,), (Type{Int},))
(true,)

```

---

<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: [November 17, 2018, 1:32pm UTC](https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636/4 "2018-11-17T13:32:31Z")

</div>

The issue you are facing is the same as

```julia
julia> (Float64, ) isa Tuple{Type{<:AbstractFloat}}
false

```

I don’t think you can use `Type` except in the outermost position.

You can use a `Tuple` type and form the `Union` outside, eg

```julia
julia> Tuple{Float64, Int} isa (Type{Tuple{T,S}} where {T <: AbstractFloat, S <: Integer})
true

```

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [November 17, 2018, 3:12pm UTC](https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636/5 "2018-11-17T15:12:28Z")

</div>

thanks a lot!

just misunderstood how `isa` works obviously

---

<div class="post-metadata">

### Author: ![schlichtanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schlichtanders/32/32145_2.png) [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)
#### Post date: [November 17, 2018, 4:46pm UTC](https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636/6 "2018-11-17T16:46:48Z")

</div>

still there is confusion on my side.

Why is the following not working?

```julia
julia> (Int, String) :: Tuple{Type{Int}, Type{String}}
ERROR: TypeError: in typeassert, expected Tuple{Type{Int64},Type{String}}, got Tuple{DataType,DataTy
pe}

```

---

<div class="post-metadata">

### Author: ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)
#### Post date: [July 26, 2023, 10:06am UTC](https://discourse.julialang.org/t/tuple-type-dont-inherit-as-expected/17636/7 "2023-07-26T10:06:55Z")

</div>

Sorry for reviving this ancient thread, but I just stumbled upon this question on the search for something else and just would like to know what’s going on in the example by @schlichtanders 😅

The answers so far didn’t really explain the reasons for the behavior.

Is this behavior expected (checked in Julia 1.8 and 1.9)?

```julia
julia> (Int,) isa Tuple{Type}
true

julia> (Int,) isa Tuple{Type{Int}}
false

```

My understanding so far was that `X isa T` implies that `(X,) isa Tuple{T}`. The example shows that this is not true, and it seems related to how `Type` works. But it feels like the implication should be true, given that `Tuple` is used to represent function signatures and e.g. the following works

```julia
julia> foo(t::Type{Int}) = println(t);

julia> foo(Int)
Int64

julia> foo(Float64)
ERROR: MethodError: no method matching foo(::Type{Float64})

```

More specifically, the method signature doesn’t match a tuple with the actual inputs to the function call

```julia
julia> (foo, Int) isa only(methods(foo)).sig
false

```

But it does (as far as I can tell) for “normal” signatures involving no `Type`:

```julia
julia> baz(x::Int) = 2x;

julia> (baz, 1) isa only(methods(baz)).sig
true

```

What makes `Type` special in this regard?
