This is a prototype of an IO subtype that prints Julia's parametric types as a tree. This is intended to support omitting or folding types when printing stacktraces, c.f. JuliaLang/julia#48444 (comment).
Demo:
using TypeTreesIO, AbstractTrees
AbstractTrees.children(node::TypeTreeNode) = (v = node.children; v === nothing ? () : v)
AbstractTrees.nodevalue(node::TypeTreeNode) = node.name
julia> obj = view([1, 2, 3], 1:2); # a parametric type
julia> println(typeof(obj)) # what is that type?
SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{Int64}}, true}
julia> ttio = TypeTreeIO(); # create the IO object that assembles a tree-of-strings structure
julia> print(ttio, typeof(obj)); # build the tree
julia> print_tree(ttio.tree) # show the tree structure (from AbstractTrees)
"SubArray"
├─ "Int64"
├─ "1"
├─ "Vector"
│ └─ "Int64"
├─ "Tuple"
│ └─ "UnitRange"
│ └─ "Int64"
└─ "true"
julia> println(IOContext(stdout, :type_maxwidth=>55), ttio.tree)
SubArray{Int64, 1, Vector{…}, Tuple{…}, true}
julia> println(IOContext(stdout, :type_maxwidth=>60), ttio.tree)
SubArray{Int64, 1, Vector{Int64}, Tuple{UnitRange{…}}, true}