# Base.return\_types function

**URL:** <https://discourse.julialang.org/t/base-return-types-function/35995>\
**Category:** General Usage\
**Created:** [March 15, 2020, 12:54am UTC](https://discourse.julialang.org/t/base-return-types-function/35995 "2020-03-15T00:54:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [March 15, 2020, 12:54am UTC](https://discourse.julialang.org/t/base-return-types-function/35995/1 "2020-03-15T00:54:29Z")

</div>

I have two questions about the following experiment:

1. Why are there so many more possibilities with `AbstractArray`? Is it correct?
2. Why doesn’t it return unique results? Maybe it should.

```julia
julia> Base.return_types(iterate, Tuple{AbstractArray{Int,1}})
11-element Array{Any,1}:
 Union{Nothing, Tuple{Any,Int64}}                                        
 Union{Nothing, Tuple{Any,Any}}                                          
 Union{Nothing, Tuple{Any,Any}}                                          
 Union{Nothing, Tuple{Any,Any}}                                          
 Any                                                                     
 Any                                                                     
 Union{Nothing, Tuple{Int64,Int64}}                                      
 Union{Nothing, Tuple{Any,Int64}}                                        
 Union{Nothing, Tuple{Int64,Tuple{Int64,UInt64}}}                        
 Union{Nothing, Tuple{Any,Union{Tuple{Int64,Any}, Tuple{Int64,Any,Any}}}}
 Any                                                                     

julia> Base.return_types(iterate, Tuple{Array{Int,1}}) |> unique
1-element Array{Any,1}:
 Union{Nothing, Tuple{Int64,Int64}}

```

---

<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:** [March 15, 2020, 8:34am UTC](https://discourse.julialang.org/t/base-return-types-function/35995/2 "2020-03-15T08:34:47Z")

</div>

Generally an `AbstractArray` could be a lot of things (eg linear or cartesian indexing, various implementations), so I am not sure the compiler could tell you much more. Using `Base.return_types` is generally discouraged even for concrete types, but for abstract ones it is even less meaningful.

I am not sure why you think `Base.return_types` should return a single-element vector in this case.

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [March 15, 2020, 8:47am UTC](https://discourse.julialang.org/t/base-return-types-function/35995/3 "2020-03-15T08:47:06Z")

</div>

Please let me elaborate. The [interface for iterate](https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-iteration-1) requires that the function returns either `nothing` or a tuple of (value, state). Without knowing how the concrete types are implemented, I still expect the type of the next value to be an Int. Hence `Union{Nothing, Tuple{Int64,anything}}` makes sense to me. But I can’t see how `Union{Nothing, Tuple{Any,Any}}` satisfies the interface contract. Likewise for others.

Sorry, I pasted in the wrong example in the second case. I meant to ask why the first case returned 11 elements rather than 6.

```julia
julia> Base.return_types(iterate, Tuple{AbstractArray{Int,1}}) |> unique
6-element Array{Any,1}:
 Union{Nothing, Tuple{Any,Int64}}                                        
 Union{Nothing, Tuple{Any,Any}}                                          
 Any                                                                     
 Union{Nothing, Tuple{Int64,Int64}}                                      
 Union{Nothing, Tuple{Int64,Tuple{Int64,UInt64}}}                        
 Union{Nothing, Tuple{Any,Union{Tuple{Int64,Any}, Tuple{Int64,Any,Any}}}}

```

---

<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:** [March 15, 2020, 9:07am UTC](https://discourse.julialang.org/t/base-return-types-function/35995/4 "2020-03-15T09:07:20Z")

</div>

> [@tk3369](#):
>
> But I can’t see how `Union{Nothing, Tuple{Any,Any}}` satisfies the interface contract.

`Base.return_types` is not guaranteed to return the narrowest possible types.

Since `Int <: Any`, this is valid.
