# Prepending a type to an array

**URL:** <https://discourse.julialang.org/t/prepending-a-type-to-an-array/83140>\
**Category:** General Usage\
**Created:** [June 21, 2022, 7:20pm UTC](https://discourse.julialang.org/t/prepending-a-type-to-an-array/83140 "2022-06-21T19:20:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yly](https://avatars.discourse-cdn.com/v4/letter/y/b9e5f3/32.png) [@Yly](https://discourse.julialang.org/u/Yly)\
**Post date:** [June 21, 2022, 7:20pm UTC](https://discourse.julialang.org/t/prepending-a-type-to-an-array/83140/1 "2022-06-21T19:20:44Z")

</div>

In reading about [mixture models](https://juliastats.org/Distributions.jl/stable/mixture/#Distributions.components-Tuple%7BAbstractMixtureModel%7D) in `Distributions.jl`, I found this code snippet:  
`Normal[Normal(-2.0, 1.2), Normal(0.0, 1.0), Normal(3.0, 2.5)]`  
This syntax is unfamiliar to me. The only documentation I can find is a brief mention in the Julia [manual page for arrays](https://docs.julialang.org/en/v1/manual/arrays/#man-comprehensions) about prepending a type to an array.

What does the `Normal` in front of the array in the above snippet do, in detail? Is there documentation somewhere?

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [June 21, 2022, 7:31pm UTC](https://discourse.julialang.org/t/prepending-a-type-to-an-array/83140/2 "2022-06-21T19:31:54Z")

</div>

Probably nothing in this case since the elements are already of type `Normal`.

```julia
julia> a = [Float32(1), Float32(2), Float32(3)]
3-element Vector{Float32}:
 1.0
 2.0
 3.0

julia> b = Float32[1, 2, 3]
3-element Vector{Float32}:
 1.0
 2.0
 3.0

julia> eltype(a)
Float32

julia> eltype(b)
Float32

```

A type declaration in front of the array limits what types can be stored in the array (usually for performance or error checking).

```julia
julia> c = [1, "Hello", 3]
3-element Vector{Any}:
 1
  "Hello"
 3

julia> d = Float32[1, "Hello", 3]
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Float32

julia> eltype(c)
Any

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 21, 2022, 7:33pm UTC](https://discourse.julialang.org/t/prepending-a-type-to-an-array/83140/3 "2022-06-21T19:33:19Z")

</div>

Here’s the relevant documentation: [Multi-dimensional Arrays · The Julia Language](https://docs.julialang.org/en/v1/manual/arrays/#Typed-array-literals)
