Graphical representation of Haskell code

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. http://www.haskell.org/arrows/index.htm 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:
[image: Haskell schematic_html_m20060f13.gif] Or a curried version: [image: Haskell schematic_html_5155f0eb.gif] The function (+1) then is: [image: Haskell schematic_html_m68795eb7.gif] The function map could be drawn like this : [image: Haskell schematic_html_m28c92a58.gif] Or like this: [image: Haskell schematic_html_m6ae433ea.gif] And the entire function map (+1) could be represented as: [image: 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

On 23 March 2010 10:02, Dupont Corentin
I’m relatively new to Haskell.
Welcome!
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.
1) Because no-one has written such a tool yet (though someone has suggested doing one as a GSoC project). 2) I'm of the opinion that unless you just use it on small snippets, the generated images will be too large and unweildy.
This could be done entirely automatically from the types of the functions.
Except not everyone provides type signatures for their functions; whilst it may be possible to use the GHC API to infer these type signatures, my understanding is that it's preferable to use other parsers such as haskell-src-exts as the GHC API is unstable. [shameless plug] My SourceGraph (http://hackage.haskell.org/package/SourceGraph) tool does function call visualisation as part of its analyses. [/shameless plug] -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Reminds me of To Dissect a Mockingbird [http://dkeenan.com/Lambda/].
On Tue, Mar 23, 2010 at 7:12 AM, Ivan Miljenovic
On 23 March 2010 10:02, Dupont Corentin
wrote: I’m relatively new to Haskell.
Welcome!
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.
1) Because no-one has written such a tool yet (though someone has suggested doing one as a GSoC project). 2) I'm of the opinion that unless you just use it on small snippets, the generated images will be too large and unweildy.
This could be done entirely automatically from the types of the functions.
Except not everyone provides type signatures for their functions; whilst it may be possible to use the GHC API to infer these type signatures, my understanding is that it's preferable to use other parsers such as haskell-src-exts as the GHC API is unstable.
[shameless plug] My SourceGraph (http://hackage.haskell.org/package/SourceGraph) tool does function call visualisation as part of its analyses. [/shameless plug]
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

I've proposed to do it at this GSOC. More exactly, it is still in the
feedback phase, I'll integrate all feedback in another blog post and in an
application for GSOC tomorrow. If you want to read about it in this stage,
you can visit my blog [0]. Feedback on reddit can be seen here[1].
The pictures from Ross Paterson were one of the reasons for my idea.
[0]: http://pgraycode.wordpress.com/2010/03/20/haskell-project-idea/
[1]:
http://www.reddit.com/r/haskell/comments/bg3bx/i_need_feedback_on_a_haskell_...
--
Mihai Maruseac
On Tue, Mar 23, 2010 at 1:02 AM, Dupont Corentin
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. http://www.haskell.org/arrows/index.htm
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:
[image: Haskell schematic_html_m20060f13.gif]
Or a curried version:
[image: Haskell schematic_html_5155f0eb.gif]
The function (+1) then is:
[image: Haskell schematic_html_m68795eb7.gif]
The function map could be drawn like this :
[image: Haskell schematic_html_m28c92a58.gif]
Or like this:
[image: Haskell schematic_html_m6ae433ea.gif]
And the entire function map (+1) could be represented as:
[image: 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
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Mon, Mar 22, 2010 at 7:02 PM, Dupont Corentin
Hello, I’m relatively new to Haskell. I’m wondering if it exist a tool to graphically represent Haskell code. ... Let’s try to do it on a simple example, as an exercise: f = Map (+1)
Your graphic for "f = map (+1)" seems much more complex than the corresponding code. I would agree with Ivan Miljenovic:
I'm of the opinion that unless you just use it on small snippets, the generated images will be too large and unwieldy.
The first question I would ask is /why/ would you like to visualize some Haskell code? If you want to see the high-level structure of a complex program, try SourceGraph. (I have never used it though.) On the other hand, if you are trying to visualize Haskell as part of your efforts to learn the language, then I believe it would be best to draw diagrams by hand, rather than relying on an automated tool. The kinds of things that you'll want to depict are probably going to vary considerably, depending on what you're trying to understand. Consider a few different implementations of the "map" function: -- version 1: recursion map1 :: (a -> b) -> [a] -> [b] map1 f [] = [] map1 f (x:xs) = (f x) : map1 f xs -- version 2: fold map2 :: (a -> b) -> [a] -> [b] map2 f = foldr ((:) . f) [] -- version 3: continuation passing style map3 :: (a -> b) -> [a] -> [b] map3 f xs = map' (\x y -> f x : y) xs where map' k [] = [] map' k (y:ys) = k y (map' k ys) -- version 4: list comprehension map4 :: (a -> b) -> [a] -> [b] map4 f xs = [f x | x <- xs] -- version 5: list monad map5 :: (a -> b) -> [a] -> [b] map5 f xs = xs >>= (return . f) These all do exactly the same thing, but each one uses different techniques. If I'm trying to learn (or teach) Haskell, I would probably need a slightly different visual "language" for each one in order to capture the most relevant concepts in a useful way. How would you visualize them? @Mihai Maruseac: I think a visual debugger would be a wonderful idea. You may want to consider how a visual debugger would work with each of these versions of map. :-) You might also consider several versions of factorial :-) http://www.willamette.edu/~fruehr/haskell/evolution.html -- Ron

Hello All I seem to remember the graphical notation 'interaction nets' as having a well defined translation into the lambda calculus (so one wouldn't need to invent or formalize a new notation). As I'm no longer a student and don't have access to the ACM digital library I haven't been able to validate this. Maybe someone can comment? Interesting the Wikipedia page for interaction nets points to Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/INblobs-0.1.1 Best wishes Stephen
participants (6)
-
Dupont Corentin
-
Ivan Miljenovic
-
Lyndon Maydwell
-
Mihai Maruseac
-
Ronald Guida
-
Stephen Tetley