Tuesday, March 5, 2013

Print Julia Type Tree with julia_types.jl

The power of Julia is its type system and multiple dispatch for methods. Understanding the Julia type hierarchy helps write efficient code with tighter control. Curious to have a look at the complete type tree of base Julia modules, I stumbled across typetree.jl included in the "examples" section of the distribution.

Here's another version of the code named julia_types, made a bit simpler by using a tree data structure and recursion. Download it or fork it on Github.

For a list of modules given, it
  • extracts all symbols defined in the module
  • if the symbol is a "Type"
    • adds the type and all super types of the type recursively in a tree like data structure
    • each node of the tree is a complex type that holds the type representing the node and a dict to hold sub types.
  • Pretty prints the type tree

And here's the complete type tree as produced by julia_types.jl

No comments: