type cheatsheet

459 views
Skip to first unread message

harven

unread,
Sep 26, 2013, 6:04:45 AM9/26/13
to julia...@googlegroups.com
Is there a graph of the relationship between the different julia types somewhere?
Something like this cheatsheet.

If not, is there a function that given a type returns its children?

Cristóvão Sousa

unread,
Sep 26, 2013, 6:35:48 AM9/26/13
to julia...@googlegroups.com

astri...@gmail.com

unread,
Sep 26, 2013, 10:03:12 AM9/26/13
to julia...@googlegroups.com
I'm not aware of a chart, although I feel like I've seen one before. However, there are functions for exploring the type hierarchy.

~~~~
julia> super(Int64)
Signed

julia> subtypes(Signed)
5-element Array{Any,1}:
 Int128
 Int16
 Int32
 Int64
 Int8 

julia> help(super)
Base.super(T::DataType)

   Return the supertype of DataType T

julia> help(subtypes)
Base.subtypes(T::DataType)

   Return a list of immediate subtypes of DataType T.  Note that all
   currently loaded subtypes are included, including those not visible
   in the current module.
~~~~


-- Leah

John Myles White

unread,
Sep 26, 2013, 10:07:40 AM9/26/13
to julia...@googlegroups.com
I made a draft chart of the full type tree and can try to finish it over the weekend. It's huge, so it's not so easy to navigate.

-- John

harven

unread,
Sep 27, 2013, 6:45:39 PM9/27/13
to julia...@googlegroups.com
Thanks for all the answers.

I made some charts using graphviz, see them there.
The julia code generating the charts is here.
Any comments on the code is appreciated. I wrote it `scheme style`,
 I am not sure this is really correct in julia,
(for example, I use a local function declaration in the first function).

harven

unread,
Sep 30, 2013, 11:15:58 AM9/30/13
to julia...@googlegroups.com
I did some cleanup and updated my graph of all julia types. Here is the link.
https://imgur.com/U5vTDNp
Hopefully it is easier to read than the previous version.

John Myles White

unread,
Sep 30, 2013, 11:19:32 AM9/30/13
to julia...@googlegroups.com
This is really great. (And a huge improvement.) Thanks so much for doing this!

-- John

Stian Håklev

unread,
Sep 30, 2013, 11:22:16 AM9/30/13
to julia...@googlegroups.com
This looks very useful. Could you post it as an SVG or PDF (to enable us to smoothly zoom in)? Or how hard would it be to export it into something dynamic with zoom - using a JS graph library, or I even seem to remember  a "concept map" JS library on HNews a while back, where you would be able to expand and fold nodes, etc? (And of course, hyperlink to the documentation/code definition etc)? 

Perhaps make the node definitions (graphviz dot file or whatever the underlying format is) available, so others could play with this? Did you generate the file programmatically from Julia definitions (so that it can be automatically updated in the future) or by hand?

Great work!

Stian
--
http://reganmian.net/blog -- Random Stuff that Matters

John Myles White

unread,
Sep 30, 2013, 11:24:24 AM9/30/13
to julia...@googlegroups.com
Leah previously suggested using this D3 viz: http://mbostock.github.io/d3/talk/20111018/tree.html

That seems like the most accessible way to make something interactive.

-- John

John Myles White

unread,
Sep 30, 2013, 12:24:10 PM9/30/13
to julia...@googlegroups.com
Here's a first pass at making a useful D3 viz of our type tree: http://johnmyleswhite.com/typetree/tree.html

It'll need some cleanup work, but I'll probably leave that for another time. I'll put all the relevant code on GitHub soon.

-- John

On Sep 30, 2013, at 11:22 AM, Stian Håklev <sha...@gmail.com> wrote:

Stian Håklev

unread,
Sep 30, 2013, 12:33:06 PM9/30/13
to julia...@googlegroups.com
Very neat, now we need links to the Type documentation, and ideally to the type definitions on GitHub... I might play with this once you put it on GitHub (another step of my learning by doing something you don't understand at all approach :))

Jacob Quinn

unread,
Sep 30, 2013, 12:36:21 PM9/30/13
to julia...@googlegroups.com
Very cool. Yeah, it looks like some of the cleanup is recognizing abstract types. Great start though!

-Jacob

John Myles White

unread,
Sep 30, 2013, 12:45:03 PM9/30/13
to julia...@googlegroups.com
It's on GitHub now: https://github.com/johnmyleswhite/TypeTree.jl

-- John

John Myles White

unread,
Sep 30, 2013, 12:45:25 PM9/30/13
to julia...@googlegroups.com
What do you mean by recognizing abstract types? Coloring them differently from another nodes?

-- John

Jacob Quinn

unread,
Sep 30, 2013, 1:02:02 PM9/30/13
to julia...@googlegroups.com
All the abstract types are flattened to the same level in the hiearchy. For example, expanding Number shows Real, ImaginaryUnit, Complex{Float16}, Complex{Float32}, Complex{Float64}, Complex{T<:Real}, whereas I would expect for it to show Real, ImaginaryUnit, Complex (or perhaps Complex{T}). Then expand Complex to show the various Complex types. 

I guess maybe this is right though since we're talking abstract parametric types which are invariant, so it may be confusing if they're built hiearchichal. Does that make sense?

-Jacob

John Myles White

unread,
Sep 30, 2013, 1:04:40 PM9/30/13
to julia...@googlegroups.com
That does make sense. I don't have enough feel for how to reason about parametric types to know whether we could have a Complex{T} type from which the specific parameterizations descend. The type hierarchy you're seeing reflects what subtypes() produces.

-- John

harven

unread,
Sep 30, 2013, 1:43:50 PM9/30/13
to julia...@googlegroups.com
@Stian

Yes it is programatically generated. The updated code can be downloaded at
http://pastebin.com/yRrmJqSr

Assuming you have the dot utility from the graphviz package installed,
you can generate an svg graph with the command

julia> makegraph(Any, "alltypes.dot", "svg")

This produces both the .dot file and the svg file. The generation takes 3s on a 4 years old dell laptop.
I guess that files are automatically converted to jpg on imgur, so I don't have a mean to post the svg.

ggggg

unread,
Sep 30, 2013, 1:48:32 PM9/30/13
to julia...@googlegroups.com
This looks really nice.

Here is a case where expanding a node leads to overlapping text: http://s21.postimg.org/4974e10x3/johnmyleswhite_com_typetree_tree_html_2.png

John Myles White

unread,
Oct 2, 2013, 5:20:06 PM10/2/13
to julia...@googlegroups.com
Thanks for the heads up. I will try to clean this up more later this month, but it may take some time.

-- John
Reply all
Reply to author
Forward
0 new messages