# Type parameters are treated differently based on their names

**URL:** <https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972>\
**Category:** New to Julia\
**Tags:** type\
**Created:** [January 21, 2022, 10:50am UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972 "2022-01-21T10:50:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ranlajetech](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranlajetech/32/43225_2.png) [@Ranlajetech](https://discourse.julialang.org/u/Ranlajetech)\
**Post date:** [January 21, 2022, 10:50am UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972/1 "2022-01-21T10:50:21Z")

</div>

```julia
julia> Type === Type{T} where T
true

julia> Type === Type{S} where S
false

julia> Type === Type{t} where t
false

```

This is what I got in REPL(Julia v1.7.1, Windows10 64-bit). I got the same result running it as a file. In a fresh REPL, there is

```julia
julia> Type === Type{S} where S
false

```

I can get the true result if and only if using T as the type parameter. Why do they act differently? Is this a bug?

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [January 21, 2022, 10:53am UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972/2 "2022-01-21T10:53:44Z")

</div>

Looks fine for me.

```julia
julia> Type == Type{T} where T
true

julia> Type == Type{S} where S
true

julia> Type == Type{t} where t
true

```

---

<div class="post-metadata">

**Author:** ![Ranlajetech](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranlajetech/32/43225_2.png) [@Ranlajetech](https://discourse.julialang.org/u/Ranlajetech)\
**Post date:** [January 21, 2022, 10:56am UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972/3 "2022-01-21T10:56:43Z")

</div>

It is ‘===’, not ‘==’ in my code. @goerch

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [January 21, 2022, 11:03am UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972/4 "2022-01-21T11:03:00Z")

</div>

Hi @Ranlajetech ,

the change was intentional. I do not immediately find a good page in the reference manual, but [this](https://stackoverflow.com/questions/38601141/what-is-the-difference-between-and-comparison-operators-in-julia/38602012) discusses differences between equality (`==`) and identity (`===`).

---

<div class="post-metadata">

**Author:** ![Ranlajetech](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ranlajetech/32/43225_2.png) [@Ranlajetech](https://discourse.julialang.org/u/Ranlajetech)\
**Post date:** [January 21, 2022, 11:23am UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972/5 "2022-01-21T11:23:34Z")

</div>

I have learnt about the difference between equality and identity, but I don’t understand why identifier T is so special in this piece of code that I can’t get true using any other parameter name. @goerch

---

<div class="post-metadata">

**Author:** ![JonasIsensee](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonasisensee/32/4704_2.png) [@JonasIsensee](https://discourse.julialang.org/u/JonasIsensee)\
**Post date:** [January 21, 2022, 11:30am UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972/6 "2022-01-21T11:30:40Z")

</div>

```julia
julia> dump(Type)
UnionAll
  var: TypeVar
    name: Symbol T
    lb: Union{}
    ub: Any
  body: Type{T} <: Any

```

The default `Type` is defined using `T` as the type parameter symbol.

```julia
julia> dump(Type{S} where S)
UnionAll
  var: TypeVar
    name: Symbol S
    lb: Union{}
    ub: Any
  body: Type{S} <: Any

```

Both cases should be functionally the same , hence `==` holds, but since the typevar symbol is carried around they are not identical.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [January 21, 2022, 12:13pm UTC](https://discourse.julialang.org/t/type-parameters-are-treated-differently-based-on-their-names/74972/7 "2022-01-21T12:13:09Z")

</div>

> [@JonasIsensee](#):
>
> The default `Type` is defined using `T` as the type parameter symbol.

Half jokingly, maybe we should do

```julia
macro UnionAll(var, expr)
    Expr(:where, esc(expr), esc(var))
end

T = gensym()
TypeVarT = TypeVar(T)
TypeT = Type{TypeVarT}
MyType = UnionAll(TypeVarT, @UnionAll T TypeT)

MyType === MyType{T} where T

```

instead? BTW, for these kind of questions I always need the help of [https://github.com/JuliaLang/julia/blob/master/test/subtype.jl](https://github.com/JuliaLang/julia/blob/master/test/subtype.jl)…
