# \`\`Any\[1, 1.0\]\`\` is valid code, but I can't find why in the docs

**URL:** <https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 22, 2019, 3:54pm UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485 "2019-05-22T15:54:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henri\_Laurie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henri_laurie/32/5079_2.png) [@Henri\_Laurie](https://discourse.julialang.org/u/Henri_Laurie)\
**Post date:** [May 22, 2019, 3:54pm UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/1 "2019-05-22T15:54:36Z")

</div>

I love the fact that I can decorate `[1.0, 1]` as `Any[1, 1.0]` and `Real[1, 1.0]` and have mixed number type as elements.

But I can’t find where in the docs this is described, and I am not even sure where in the docs it should go—is it part of the discussion of types, or of arrays, or both?

I expected decoration to work also for user-defined types, and it does.

---

<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:** [May 22, 2019, 4:03pm UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/2 "2019-05-22T16:03:37Z")

</div>

Looking for  
[https://docs.julialang.org/en/v1/manual/arrays/#Typed-array-initializers-1](https://docs.julialang.org/en/v1/manual/arrays/#Typed-array-initializers-1)  
?

---

<div class="post-metadata">

**Author:** ![Henri\_Laurie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henri_laurie/32/5079_2.png) [@Henri\_Laurie](https://discourse.julialang.org/u/Henri_Laurie)\
**Post date:** [May 22, 2019, 6:02pm UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/3 "2019-05-22T18:02:17Z")

</div>

Indeed! Thanks!

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [May 22, 2019, 10:55pm UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/4 "2019-05-22T22:55:36Z")

</div>

Note however, that operations on Arrays like these can be really slow because of type instability and you’re usually much better off using a Tuple or a different data structure.

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [May 23, 2019, 7:49am UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/5 "2019-05-23T07:49:30Z")

</div>

```julia
julia> DuckTyping = Any
Any

julia> DuckTyping[3,4.5,"tiger",big(6),big(77.777)]
5-element Array{Any,1}:
  3                                               
  4.5                                             
   "tiger"                                        
  6                                               
 77.7770000000000010231815394945442676544189453125

```

---

<div class="post-metadata">

**Author:** ![Henri\_Laurie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henri_laurie/32/5079_2.png) [@Henri\_Laurie](https://discourse.julialang.org/u/Henri_Laurie)\
**Post date:** [May 23, 2019, 8:37am UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/6 "2019-05-23T08:37:22Z")

</div>

Oh, agreed! I stumbled across this because I am writing a course for Julia as a first programming language, and it raises lots of flags for me.  
— `T[...]` looks indexing  
— but is in fact a constructor, which is a function, which should have round brackets, as far as beginners are concerned  
— and in any case I want to say as little as possible about the type system

I’m trying to follow the slogan “Small steps, leave nothing out, everything makes sense” so that rank beginners who are easily put off will find that they can follow along without missing anything. Of course that is not suitable for the hot-shots who become professional programmers, but I believe programming should be like singing and dancing: everybody should be able to do it in at least a small way.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 23, 2019, 8:44am UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/7 "2019-05-23T08:44:12Z")

</div>

> [@Henri\_Laurie](#):
>
> — `T[...]` looks indexing

It actually is:

```julia
julia> getindex(Float64, 1, 2, 3)
3-element Array{Float64,1}:
 1.0
 2.0
 3.0

```

see [https://github.com/JuliaLang/julia/blob/efd794e199994237e1278a69b38ddad9f949b6b5/base/array.jl#L321-L363](https://github.com/JuliaLang/julia/blob/efd794e199994237e1278a69b38ddad9f949b6b5/base/array.jl#L321-L363)

---

<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:** [May 23, 2019, 8:50am UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/8 "2019-05-23T08:50:28Z")

</div>

> [@Henri\_Laurie](#):
>
> `T[...]` looks indexing

Possibly (and as noted above by @fredrikekre , also in terms of the implementation), but it can also be considered an extension of the vector constructor `[1, 2, ...]`. `[]`s are used for other purposes, too, eg [comprehensions](https://docs.julialang.org/en/v1/manual/arrays/#Comprehensions-1).

Many languages use building blocks of syntax for multiple purposes, especially if it does not create an ambiguity.

> [@Henri\_Laurie](#):
>
> so that rank beginners who are easily put off will find that they can follow along without missing anything

In Julia it is very easy to stumble upon advanced concepts while evaluating seemingly simple code. Beginners in Julia, even if they are experienced programmers in other languages, tend to miss _a lot_ initially, just because the language is quite different from what they may be used to. The trick is not to mind missing things initially, and then get them in a second, or third pass.

---

<div class="post-metadata">

**Author:** ![Henri\_Laurie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henri_laurie/32/5079_2.png) [@Henri\_Laurie](https://discourse.julialang.org/u/Henri_Laurie)\
**Post date:** [May 23, 2019, 10:41am UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/9 "2019-05-23T10:41:46Z")

</div>

I’d agree, for motivated and relaxed learners. My course has the tentative title “Julia Programming for Nervous Beginners” and I am trying to find a balance where advanced topics, when they come up, can be safely broken into “this is the bit that concerns you” and “the rest” without in any way generating anxiety in the learners that may be prone to that.

So far, the type system is where I find it the hardest to design a sequence that is somewhat satisfying. My plan is to do functions very early (before for loops, for example), introduce multiple dispatch by an example, and attempt to discuss the type system only in terms of helping with multiple dispatch (ignoring compiler optimisation in particular).

---

<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:** [May 23, 2019, 10:51am UTC](https://discourse.julialang.org/t/any-1-1-0-is-valid-code-but-i-cant-find-why-in-the-docs/24485/10 "2019-05-23T10:51:42Z")

</div>

This sounds like a reasonable plan. While I think that 90% of Julia programming is about “cooperating with the compiler”, I agree that this may very confusing for beginners (sometimes it is also challenging for seasoned users).
