Hello,

I’m relatively new to Haskell.

I’m wondering if it exist a tool to graphically represent Haskell code.


Look at the little graphics at: http://www.haskell.org/arrows/index.html (and following pages) from Ross Paterson.

If found these very useful to understand the Arrow monad.


Why not automatise this in a tool? Such a tool could draw a graphic from the code of a program.

This could be done entirely automatically from the types of the functions.


Let’s try to do it on a simple example, as an exercise:

f = Map (+1)


How does this function could be represented?


It contains the (+) function.

This function has the type (+) :: Num a => a -> a -> a.

From this type we could deduce the graphic:

Haskell schematic_html_m20060f13.gif

Or a curried version:

Haskell schematic_html_5155f0eb.gif


The function (+1) then is:

Haskell schematic_html_m68795eb7.gif


The function map could be drawn like this :

Haskell schematic_html_m28c92a58.gif

Or like this:


Haskell schematic_html_m6ae433ea.gif


And the entire function map (+1) could be represented as:

Haskell schematic_html_macb1643.gif



Thanks to the advanced type system of Haskell, everything could be deduced from the type signatures.


Such a tool would be recreational and educational.

One could zoom in and out in a program, to display more or less details.

This could help understand a program, globally or locally.


We could even imagine a constructive version of the tool, where the programmer would draw functions from a toolbox, and stick them into the graphic!


Does a tool approaching this already exist? If not, would it be a good project?


Cheers,

Corentin