Prepending a type to an array

In reading about mixture models 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 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?

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

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> 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
1 Like

Here’s the relevant documentation: Multi-dimensional Arrays · The Julia Language

2 Likes