# What on earth does Any\[...\] do?

**URL:** https://discourse.julialang.org/t/what-on-earth-does-any-do/7625
**Category:** General Usage
**Created:** [December 8, 2017, 3:04pm UTC](https://discourse.julialang.org/t/what-on-earth-does-any-do/7625 "2017-12-08T15:04:56Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [December 8, 2017, 3:52pm UTC](https://discourse.julialang.org/t/what-on-earth-does-any-do/7625/5 "2017-12-08T15:52:07Z")

</div>

Interesting! This is a bit subtle, but it’s a natural result of arrays attempting to promote their contents to a common type.

```julia
julia> Any[[1,2,3], ["1","2","3"], [1.0,2.0,3.0] ]
3-element Array{Any,1}:
 [1, 2, 3]
 String["1", "2", "3"]
 [1.0, 2.0, 3.0]

julia> [[1,2,3], ["1","2","3"], [1.0,2.0,3.0] ]
3-element Array{Array{Any,1},1}:
 Any[1, 2, 3]
 Any["1", "2", "3"]
 Any[1.0, 2.0, 3.0]

```

In the first case, the outer array has explicit element type `Any` so its elements are taken as is when constructing the array. In the second case, the outer array has no explicit element type so `typejoin` is called to try to find a “reasonable” common element type – which is `Vector{Any}` since all of the things passed to it are vectors but they don’t have a common element type. So they’re all converted to the type `Vector{Any}` before construction.

The thing that’s questionable here is whether arrays should recursively promote to a common type like this when it ends up “pessimizing” their individual element types so much. The motivation for the array promotion rule is (more common) cases like this:

```julia
julia> [[1, 2, 3], [1, 0.5, 0.25, 0.125], [-1, -2] ]
3-element Array{Array{Float64,1},1}:
 [1.0, 2.0, 3.0]
 [1.0, 0.5, 0.25, 0.125]
 [-1.0, -2.0]

```

Here’s it’s much better in terms of types and performance to convert all of the internal arrays to a single common concrete element type. I’ve filed an issue about this: [#24988](https://github.com/JuliaLang/julia/issues/24988) since it’s worth considering changing the array promotion rule here.

---

_[View the full topic](https://discourse.julialang.org/t/what-on-earth-does-any-do/7625)._
