# Correct argument type for ::Array{Array{\<:Real,1},1})

**URL:** <https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164>\
**Category:** General Usage\
**Created:** [January 9, 2020, 4:40pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164 "2020-01-09T16:40:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [January 9, 2020, 4:40pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164/1 "2020-01-09T16:40:10Z")

</div>

I would like to understand why

```julia
function foo(A::Array{Array{<:Real,1},1}) end

```

does not accept

```julia
foo(fill(Float64[],10))

```

I know that

```julia
function foo(A::Array{Array{T,1},1}) where T <: Real end

```

works but I need to understand why. I thought I understood julia parametric types but apparently not.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [January 9, 2020, 5:20pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164/2 "2020-01-09T17:20:01Z")

</div>

This is because

```julia
julia> Array{Array{<:Real,1},1} == Array{Array{T,1} where T<:Real,1}
true

```

but what you really want is, as you noted: `Array{Array{T,1}} where {T<:Real,1}`.

---

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [January 9, 2020, 5:28pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164/3 "2020-01-09T17:28:29Z")

</div>

you mean `<:Real` right ?

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [January 9, 2020, 5:32pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164/4 "2020-01-09T17:32:28Z")

</div>

Yes, sorry. I guess I answered a bit too hastily. I’ll edit my post to fix this.

The point was that it’s merely an issue with syntax and where the “`where`” clause is introduced when using the shortened notation `A{B{<:C}}`. This experience should not lead you to question your understanding of invariance and such topics.

---

<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:** [January 9, 2020, 5:52pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164/5 "2020-01-09T17:52:03Z")

</div>

`Array{Array{<:Real,1},1}` is an array of arrays, where each sub-array might have a _different_ element type. But I think that’s likely to be kind of confusing, so let’s simplify with some helpful names. I think you’ll agree that your initial argument type could be written as:

```julia
julia> A = Array{<:Real, 1}
Array{#s2,1} where #s2<:Real

julia> B = Array{A, 1}
Array{Array{#s2,1} where #s2<:Real,1}

```

The type of `fill(Float64[], 10)` is:

```julia
julia> typeof(fill(Float64[], 10))
Array{Array{Float64,1},1}

```

So we can rewrite that as:

```julia
julia> C = Array{Float64, 1}
Array{Float64,1}

julia> D = Array{C, 1}
Array{Array{Float64,1},1}

```

An array of floats is a subtype of `Array{<:Real}`:

```julia
julia> C <: A
true

```

But that doesn’t mean that `Array{C, 1} <: Array{A, 1}` :

```julia
julia> Array{C, 1} <: Array{A, 1}
false

```

for exactly the same reason that:

```julia
julia> Array{Float64, 1} <: Array{Real, 1}
false

```

---

<div class="post-metadata">

**Author:** ![bashonubuntu](https://avatars.discourse-cdn.com/v4/letter/b/f19dbf/32.png) [@bashonubuntu](https://discourse.julialang.org/u/bashonubuntu)\
**Post date:** [January 9, 2020, 6:02pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164/6 "2020-01-09T18:02:24Z")

</div>

Directly from [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/index.html#Parametric-Types-1) we see

```julia
Warning

This last point is *very* important: even though `Float64 <: Real` we **DO NOT** have `Point{Float64} <: Point{Real}` .

```

Your issue is just a special case of the above warning as @rdeits elucidated so clearly above.

---

<div class="post-metadata">

**Author:** ![HenriDeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrideh/32/8316_2.png) [@HenriDeh](https://discourse.julialang.org/u/HenriDeh)\
**Post date:** [January 9, 2020, 6:03pm UTC](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164/7 "2020-01-09T18:03:45Z")

</div>

Okay, thank you I got it. Actually it made sense as soon as you said that each Array could have a different element type. Sweet.
