# Vector of a union of two different numeric types---Vector{Union{Int64, Float64}}

**URL:** <https://discourse.julialang.org/t/vector-of-a-union-of-two-different-numeric-types-vector-union-int64-float64/14642>\
**Category:** General Usage\
**Created:** [September 6, 2018, 8:50pm UTC](https://discourse.julialang.org/t/vector-of-a-union-of-two-different-numeric-types-vector-union-int64-float64/14642 "2018-09-06T20:50:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaraujo71](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaraujo71/32/10635_2.png) [@aaraujo71](https://discourse.julialang.org/u/aaraujo71)\
**Post date:** [September 6, 2018, 8:50pm UTC](https://discourse.julialang.org/t/vector-of-a-union-of-two-different-numeric-types-vector-union-int64-float64/14642/1 "2018-09-06T20:50:59Z")

</div>

Dear Julia Experts, please, what’s wrong with the following? Can’t I make a vector that is a union of two different numerical types, i.e. a vector of either `Int64` or ` Float64` elements?

```julia
IntFloat = Union{Int64, Float64}
function fun(x::Vector{IntFloat})
    println(x)
end
fun(Int64[1, 2, 3])
fun(Float64[1, 2, 3])

```

---

<div class="post-metadata">

**Author:** ![simonbyrne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simonbyrne/32/19_2.png) [@simonbyrne](https://discourse.julialang.org/u/simonbyrne)\
**Post date:** [September 6, 2018, 8:53pm UTC](https://discourse.julialang.org/t/vector-of-a-union-of-two-different-numeric-types-vector-union-int64-float64/14642/2 "2018-09-06T20:53:16Z")

</div>

Type parameters are invariant, see [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/index.html#Parametric-Composite-Types-1)

You need to define `fun` as:

```julia
function fun(x::Vector{T}) where {T<:Union{Float64,Int64}}
    println(x)
end

```

---

<div class="post-metadata">

**Author:** ![aaraujo71](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aaraujo71/32/10635_2.png) [@aaraujo71](https://discourse.julialang.org/u/aaraujo71)\
**Post date:** [September 6, 2018, 9:30pm UTC](https://discourse.julialang.org/t/vector-of-a-union-of-two-different-numeric-types-vector-union-int64-float64/14642/3 "2018-09-06T21:30:52Z")

</div>

thank you 🙂
