Consider this weird Julia session:
$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.5.3 (2020-11-09)
_/ |\__'_|_|_|\__'_| |
|__/ |
julia> function f1()
local t = Union{}
for _ in Base.OneTo(10)
println(t)
t = Type{t}
end
return nothing
end
f1 (generic function with 1 method)
julia> function f2()
local t = Union{}
for _ in Base.OneTo(10)
println(t)
t = typeof(t)
end
return nothing
end
f2 (generic function with 1 method)
julia> f1()
Union{}
Type{Union{}}
Type{Core.TypeofBottom}
Type{Type{Core.TypeofBottom}}
Type{Type{Type{Core.TypeofBottom}}}
Type{Type{Type{Type{Core.TypeofBottom}}}}
Type{Type{Type{Type{Type{Core.TypeofBottom}}}}}
Type{Type{Type{Type{Type{Type{Core.TypeofBottom}}}}}}
Type{Type{Type{Type{Type{Type{Type{Core.TypeofBottom}}}}}}}
Type{Type{Type{Type{Type{Type{Type{Type{Core.TypeofBottom}}}}}}}}
julia> f2()
Union{}
Core.TypeofBottom
DataType
DataType
DataType
DataType
DataType
DataType
DataType
DataType
I’ve got some questions:
-
Why does the second iteration of
f1()
useType{Union{}}
, but subsequent iterations instead useCore.TypeofBottom
? -
Why does
f2()
not use Type? -
What’s up with
DataType
, isn’t that for named types? To be specific, the documentation says “DataType represents explicitly declared types that have names, explicitly declared supertypes, and, optionally, parameters.” -
Are there any legitimate uses for such constructs (
Type{Type{ ... Type{X} ... }}
)