🎓 A1Learner
🔍
0 of 48 lessons completed

Julia Type Hierarchies

A type hierarchy is a chain of types from a narrow type up to a broad parent type. Each step up groups more values together.

The chain starts at Int64

The parent of Int64 is Signed. The parent of Signed is Integer.

println(supertype(Int64))
println(supertype(Signed))

The chain ends at Any

Integer climbs to Real, then to Number, then to Any. Each step is one parent up.

println(supertype(Integer))
println(supertype(Real))
println(supertype(Number))

A value belongs to its whole chain

The value 5 is an Integer, a Real, and a Number. Each test is true.

println(5 isa Integer)
println(5 isa Real)
println(5 isa Number)

Example

println(supertype(Int64))
println(supertype(supertype(Int64)))
println(supertype(supertype(supertype(Int64))))
println(5 isa Number)

Key points

  • Parent type: a parent type is the broader type directly above a type.
  • Supertype: supertype gives the parent type of a type.
  • Integer chain: Int64 sits under Signed, and Signed sits under Integer.
  • Number chain: Integer sits under Real, and Real sits under Number.
  • Top type: Number sits under Any, and Any sits above every type.

In this example, the parent of Int64 is Signed, the parent of that parent is Integer, and the next parent up is Real. The value 5 also belongs to Number, further up the same chain.

Note

a value belongs to every type in its chain.

Try it Yourself

Edit the code, then press Run.

Running is simulated · JuliaHub

Exercise

What is supertype(Int64)?