# Example for the type T3 \[see its definition in the message\]?

**URL:** https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051
**Category:** New to Julia
**Created:** [April 4, 2023, 8:56am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051 "2023-04-04T08:56:28Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Antonio\_De\_Felice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antonio_de_felice/32/48739_2.png) [@Antonio\_De\_Felice](https://discourse.julialang.org/u/Antonio_De_Felice)
#### Post date: [April 4, 2023, 8:56am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/1 "2023-04-04T08:56:28Z")

</div>

I’m really new to Julia, sorry about it.

After following the docs regarding Types, I was wondering how to build an explicit example, if possible, for the following type:

const T3 = Array{Array{T, 1} where T \<: Real, 1}

T3 is “derived” from the type T1 given in [Types · The Julia Language](https://docs.julialang.org/en/v1/manual/types/)

Sure I can define:  
a = T3() # returns the empty vector  
but I’m not able to find/build up a more non-trivial example.

In a previous similar topic  
([Correct argument type for ::Array{Array{\<:Real,1},1})](https://discourse.julialang.org/t/correct-argument-type-for-array-array-real-1-1/33164))  
I could see that:  
Array{Array{\<:Real,1}, 1} === Array{Array{T,1} where T\<:Real, 1} # returns true  
but  
Array{\<:Real,1} === Array{T,1} where T\<:Real # returns false  
and  
Array{Float64, 1} \<: Array{\<:Real, 1} # returns true  
Array{Float64,1} \<: Array{T,1} where T\<:Real # returns true

I’m still a bit confused, sorry!

Thanks a lot for your help.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [April 4, 2023, 9:22am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/2 "2023-04-04T09:22:32Z")

</div>

This page is a good starting point: [Vector{Int} \<: Vector{Real} is false??? · JuliaNotes.jl](https://m3g.github.io/JuliaNotes.jl/stable/typevariance/)

Once you have read it, perhaps the following code will make sense to you. I think `T4` (and not `T3`) is what you want to use here:

```julia
julia> const T3 = Vector{Vector{<:Real}}
Vector{Vector{T} where T<:Real} (alias for Array{Array{T, 1} where T<:Real, 1})

julia> const T4 = Vector{<:Vector{<:Real}}
Vector{<:Vector{<:Real}} (alias for Array{<:Array{<:Real, 1}, 1})

julia> v = [1, 2]
2-element Vector{Int64}:
 1
 2

julia> a = [v]
1-element Vector{Vector{Int64}}:
 [1, 2]

julia> a isa T3
false

julia> a isa T4
true

```

---

<div class="post-metadata">

### Author: ![Antonio\_De\_Felice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antonio_de_felice/32/48739_2.png) [@Antonio\_De\_Felice](https://discourse.julialang.org/u/Antonio_De_Felice)
#### Post date: [April 5, 2023, 6:51am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/3 "2023-04-05T06:51:27Z")

</div>

Thanks a lot for the page in “github.” It was very nice.

As for T3, then it seems T3 is almost an empty set, isn’t it?

As for T4, I see. I need another \<: operator.

Just as a matter of curiosity, on defining T5 as follows:

const T5 = Array{Array{T, 1}, 1} where T\<:Real

we find that

T4 === T5 # returns false

However, in many examples I tried, the same vectors belong at the same time to both T4 and T5. In the following code, one can freely replace T4 with T5, obtaining exactly the same outputs (either true or false).

[[1,2], [“hi”, “ciao”, “viv”]] isa T4, # false  
[[“hi”, “ciao”], [1//2, 2.0]] isa T4, #false  
[[“hi”, “ciao”], [1//2, 2.0], [[1,2], [2,3]]] isa T4, # false  
[[1,2], [4.5, 6.7]] isa T4, # true  
[[1,2], [4.5, 6.7, 6.1]] isa T4, # true  
[[11,4], [-1+2im, 3+4im]] isa T4, # false  
[[1.6, 2.0], [2, 3]] isa T4, # true  
[[1.5,2], [2,3.6]] isa T4, # true  
[[1; 2], [2; 3]] isa T4, # true  
[[11,4], [-1+2im, 3+4im]] isa T4, # false  
[[1, 2, 3, 4], [1.0, 4.0]] isa T4, # true  
[[1; 2]; [2; 3]] isa T4, # false  
[[1 2] [2 3]] isa T4, # false  
[[1,2], [“hi”, “ciao”]] isa T4 # false

Thanks again a lot for the nice reply.

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [April 5, 2023, 12:11pm UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/4 "2023-04-05T12:11:53Z")

</div>

Yes I think `T3` is basically useless.  
As for `T5`, for some weird reason it is different from `T3` due to the placement of the `where`:

```julia
julia> T3 = Vector{Vector{T} where T<:Real}
Vector{Vector{T} where T<:Real} (alias for Array{Array{T, 1} where T<:Real, 1})

julia> T5 = Vector{Vector{T}} where T<:Real
Array{Vector{T}, 1} where T<:Real

```

---

<div class="post-metadata">

### Author: ![Antonio\_De\_Felice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antonio_de_felice/32/48739_2.png) [@Antonio\_De\_Felice](https://discourse.julialang.org/u/Antonio_De_Felice)
#### Post date: [April 6, 2023, 1:41am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/5 "2023-04-06T01:41:22Z")

</div>

Very nice indeed [although it is indeed a bit weird].

In a mathematical sense, (I think that) if two sets have [exactly] the same elements, I would say they are equivalent, the same. So I also find it weird that T4 === T5 returns false (although I have not really shown that they share all the possible elements).

Thanks a lot for the answers I have learned a lot. Have a nice day.

---

<div class="post-metadata">

### Author: ![Antonio\_De\_Felice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antonio_de_felice/32/48739_2.png) [@Antonio\_De\_Felice](https://discourse.julialang.org/u/Antonio_De_Felice)
#### Post date: [April 7, 2023, 3:30am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/6 "2023-04-07T03:30:08Z")

</div>

I have found something which looks at least weird or just a simple mistake of mine.

All right, following your example, let me define

> `julia> const S1 = Vector{<:Vector{<:Number}}`

This is very close to what you defined T4, but it should also contain say complex numbers. All right the following line returns something I do not understand:

> `julia> [[2.8, 3.8]] isa S1, [[3+1im, 2+5im]] isa S1, [[2.8, 3.8], [3+1im, 2+5im]] isa S1`  
> `(true, true, false)`

but, as already said, I do not understand why. Some ideas about it?

To make it work I need, for example, to promote at least one of the Complex{Int} into a Complex{Float64}… but why?

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [April 7, 2023, 7:20am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/7 "2023-04-07T07:20:18Z")

</div>

Good remark! Let’s see what the type of this strange third object is (btw, don’t forget to enclose your code in triple backticks to make it easier to read, like I do):

```julia
julia> typeof([[2.8, 3.8], [3+1im, 2+5im]])
Vector{Vector} (alias for Array{Array{T, 1} where T, 1})

```

Since the two inner vectors have different element types, apparently Julia doesn’t bother to remember that they are both subtypes of `Number`, and instead recognizes the outer vector as containing `Vector{Any}` items. But we can force Julia to admit that these are indeed numbers:

```julia
julia> typeof(Vector{Number}[[2.8, 3.8], [3+1im, 2+5im]])
Vector{Vector{Number}} (alias for Array{Array{Number, 1}, 1})

```

---

<div class="post-metadata">

### Author: ![Antonio\_De\_Felice](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antonio_de_felice/32/48739_2.png) [@Antonio\_De\_Felice](https://discourse.julialang.org/u/Antonio_De_Felice)
#### Post date: [April 7, 2023, 8:22am UTC](https://discourse.julialang.org/t/example-for-the-type-t3-see-its-definition-in-the-message/97051/8 "2023-04-07T08:22:00Z")

</div>

Thanks a lot for your prompt answer. Also interesting.

By the way, adding another ComplexF64 vector fixes the bug. For example

> `julia> [[2.8, 3.8], [3+1im, 2+5im], [3, 5.0im]] isa S1`  
> `true`

Also on considering the other type you have mentioned

> `julia> const S2 = Array{Array{Number, 1}, 1};`  
> `julia> [[2.8, 3.8]] isa S2`  
> `false`

Ok, I will have to explore Julia more. In any case, it was very helpful. Thanks a lot for your time.
