Skip to content

Convenient function that shows the type hierarchy #24741

@tk3369

Description

@tk3369

I'm learning Julia and thought it would be great to see the type hierarchy easily. The subtypes function is great but it only shows one level. So I created a simple function that prints the entire subtree. Would it be good to add to Base?

julia> function subtypetree(t, level=1, indent=4)
           level == 1 && println(t)
           for s in subtypes(t)
             println(join(fill(" ", level * indent)) * string(s))
             subtypetree(s, level+1, indent)
           end
       end
subtypetree (generic function with 3 methods)

julia> subtypetree(Number)
Number
    Complex
    Real
        AbstractFloat
            BigFloat
            Float16
            Float32
            Float64
        Integer
            BigInt
            Bool
            Signed
                Int128
                Int16
                Int32
                Int64
                Int8
            Unsigned
                UInt128
                UInt16
                UInt32
                UInt64
                UInt8
        Irrational
        Rational

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions