What is difference between Type{T} and T



Hello everyone,
I have just started to learn about Julia(<:1.0).

Unfortunately, I am not able to understand the use/functionality of Type{T}, for example, in

convert(::Type{T}, a::T) where {T<:AbstractArray} = a

why cannot we use

convert(::T, a::T) where {T<:AbstractArray} = a

please excuse me if this question is too basic.


did you read the documentation?


also, for an example,



The documentation of convert is

convert(T, x)

  Convert x to a value of type T.

And an example is

julia> convert(Int, 3.0)

So you can see the first argument is a Type, so its type is Type{T}, and the second argument is an object to be converted to that type.


foo(::T, a::S) where {T,S} - the first argument of foo is a (non-usable) variable of type T, the second, namely a of type S.

foo(::Type{T}, a::S)- the first argument of foo is the type T, the second is of type S.

So, the difference between ::T and ::Type{T} is that they request either a variable of type T or a variable which is the type T itself. In julia types are data as well.

Indeed, this is a very basic question that is easily addressed by reading the documentation and actually running the code in question and seeing its effects.


Please everyone, keep in mind that this question was appropriately posted in the usage / first steps category. Even if something is documented, it’s still not a problem to ask a question about it! Hopefully the answers here help clarify things for @vickysharma0812.


Thank you for reply,
I have understood the usage and importance of Type{T}.



Type{T} is admittedly slightly unintuitive as it provides an unexpected branch in the type tree

DataType <-------- Float64
Type{Float64} <-/
julia> typeof(Float64)

julia> Float64 isa DataType

julia> Float64 isa Type{Float64} # This in comibnation with the next line might be unexpected

julia> DataType isa Type{Float64} 

which the documentation hints at by calling it “special”


Just to add on, often, when you are new to something, even if you read the documentation not everything clicks. More often than not you are unsure why some passage or sentence matters until you’ve understood the concepts. This is why it’s helpful to point to the documentation and explain briefly the concepts as well.