Is there a convenient way to visualize the Julia type tree? I know I can write a function for that...
function ttree(t::Type, indent = " ")
println(string(indent, t))
indent *= " "
for st in subtypes(t)
ttree(st, indent)
end
end
ttree(Integer)
Integer
Bool
Signed
BigInt
Int128
Int16
Int32
Int64
Int8
Unsigned
UInt128
UInt16
UInt32
UInt64
UInt8
...but Julia's strong pronunciation of multiple dispatch makes me feel like there must be some cool built-in function for that, right?
Use GraphRecipes
:
using GraphRecipes, Plots
plot(Integer, method=:tree, fontsize=10, nodeshape=:rect)
Here is an ASCII approach
using AbstractTrees
AbstractTrees.children(d::DataType) = subtypes(d)
And here it is in action
julia> print_tree(Integer)
Integer
├─ Bool
├─ Signed
│ ├─ BigInt
│ ├─ Int128
│ ├─ Int16
│ ├─ Int32
│ ├─ Int64
│ └─ Int8
└─ Unsigned
├─ UInt128
├─ UInt16
├─ UInt32
├─ UInt64
└─ UInt8
Term.jl provides a typestree
function that produces a beautiful tree of types:
But it only seems to go upwards i.e. the supertype hierarchy of a given type. An option to dig down to get lower level subtypes doesn't (as of Term v1.0.4) seem to exist. It does print out the immediate subtypes of a type, just not the levels down from those.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With