# Calling a funcion with tuple types

**URL:** <https://discourse.julialang.org/t/calling-a-funcion-with-tuple-types/1745>\
**Category:** General Usage\
**Created:** [January 28, 2017, 7:31pm UTC](https://discourse.julialang.org/t/calling-a-funcion-with-tuple-types/1745 "2017-01-28T19:31:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 28, 2017, 7:31pm UTC](https://discourse.julialang.org/t/calling-a-funcion-with-tuple-types/1745/1 "2017-01-28T19:31:28Z")

</div>

Consider the following:

```julia
julia> f{N}(x::Type{NTuple{N,Int}}) = x
f (generic function with 1 method)

julia> g{N}(x::Type{NTuple{N,Any}}) = x
g (generic function with 1 method)

julia> f(Tuple{Int,Int})
Tuple{Int64,Int64}

julia> g(Tuple{Int,Int})
ERROR: MethodError: no method matching g(::Type{Tuple{Int64,Int64}})
Closest candidates are:
  g{N}(::Type{Tuple{Vararg{Any,N}}}) at REPL[2]:1

```

I would have expected `g` to be called. Is it because of some covariance thing with `Type`?

This works:

```nohighlight
h(x::Type{T}) where T <: NTuple{N,Any} where N = x

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [January 28, 2017, 7:45pm UTC](https://discourse.julialang.org/t/calling-a-funcion-with-tuple-types/1745/2 "2017-01-28T19:45:24Z")

</div>

This isn’t anything specific to `Type` or `Tuple`. `NTuple{2,Int}` is a subtype of but isn’t `NTuple{2,Any}` which means that `Type{NTuple{2,Int}}` is not a subtype of `Type{NTuple{2,Any}}` in the same way as `Type{Int}` not being a subtype of `Type{Any}` or `Vector{Int}` not being a subtype of `Vector{Any}`.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [January 28, 2017, 9:38pm UTC](https://discourse.julialang.org/t/calling-a-funcion-with-tuple-types/1745/3 "2017-01-28T21:38:13Z")

</div>

Thank you. The following does work on 0.5 though:

```julia
julia> g{N}(x::Type{NTuple{N}}) = x
g (generic function with 1 method)

julia> g(Tuple{Int,Float64})
Tuple{Int64,Float64}

```

So I thought that replacing `NTuple{N}` with `NTuple{N, Any}` would work on 0.6.

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [January 31, 2017, 4:29pm UTC](https://discourse.julialang.org/t/calling-a-funcion-with-tuple-types/1745/4 "2017-01-31T16:29:05Z")

</div>

The v0.5 type-system was very buggy when it came to tuples. Now it can compute with the correctly, which also forces usage of the correct formulation for describing the set:

```julia
g{T <: NTuple{N, Any}}(x::Type{T}) = x

```
