Skip to content

Instantly share code, notes, and snippets.

@tk3369
Last active October 15, 2019 01:39
Show Gist options
  • Save tk3369/1b121df9bc27f58dac37d51dffb572f1 to your computer and use it in GitHub Desktop.
Save tk3369/1b121df9bc27f58dac37d51dffb572f1 to your computer and use it in GitHub Desktop.

Some notes from Julia Slack

My initial question was why this expression returns false:

julia> Vector{Any} === Vector
false

The answer is quite simply that Vector{Any} is just like any other Vector{T}, for which is a subtype of Vector. Then, we wonder what is Vector.

Mose Giodano pointed out that:

Vector is a syntactic sugar for Vector{T} where T. It's parametric, but the parameter is very much free.

We can prove it as such:

julia> Vector === (Vector{T} where T)
true

So, we can reason that Vector is also a parametric type. It's just that the parameter hasn't been specified yet.

multiple type parameters

It can get more interesting:

julia> struct Foo{T,S}
           x::T
           y::S
       end

julia> F1 = Foo{Int,S} where S
Foo{Int64,S} where S

julia> F2 = Foo{T,Int} where T
Foo{T,Int64} where T

julia> Foo{Int,Int} <: F1
true

julia> Foo{Int,Int} <: F2
true

julia> F1 <: Foo
true

julia> F2 <: Foo
true

julia> F1 <: F2
false

julia> F2 <: F1
false

UnionAll

Alex Arslan pointed out that Vector is a UnionAll type. The documentation is fairly clear about that:

  • Vector is an actual example in UnionAll doc string
  • The UnionAll in the julia reference manual explains that any paremetric type that does not fully specify all type parameters refers to a collection of parametric types - hence the name of UnionAll.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment