[Haskell-cafe] "Graphical Haskell"

Claus Reinke claus.reinke at talk21.com
Fri Jun 22 08:01:52 EDT 2007

> Since nobody gave an answer on this topic, I guess it is insane to do it in
> Haskell (at least for a newbie)? :)

not necessarily; we're all waiting for your first release?-)

> I would like to create a program that allows you to create such flow graphs,
> and then let GHC generate the code and do type inference. 

spun off from dazzle, which you've found, there's also blobs:

> Now, instead of generating Haskell code (which I could do first, would be
> easier to debug), I would like to directly create an AST, and use an Haskell
> API to communicate with GHC. 

one thing to consider: things get a little more tricky when the generated
haskell and dynamically loaded code is meant to do graphics (such as 
updating the original diagram with the state of the simulation). in particular, 
check that the gui framework actually works via that more circuituous route 
(similar problems to running in ghci instead of ghc).
> I already found out that GHC indeed has such an API, but how possible is
> this idea? Has this been done before? 

the ghc api is meant to support this kind of endeavours, and it isn't frozen
yet, either: the ghc team is happy to receive feedback about things that work 
or things that could work better.

before the ghc api, before blobs (after dazzle, though;), i did an embedding
of haskell-coloured petri nets in haskell, with a very simplistic graphical
net editor on top of wxhaskell, which generated haskell code for the net,
then called ghci to type-check and run the resulting code with a copy of
the original net graphics to update during simulation (poor man's reflection:):


it worked, but some things were annoying: 

- no high-level support for writing graph editors in wxhaskell;
    blobs aims to fix that

- awkward meta-programming and runtime reflection;
    ghc api should help a lot (but i can't see anything wrong with
    letting it work on generated source code first; optimization can
    come latter)

- wxhaskell encourages low-level dependencies, at least when
    you're writing your first wxhaskell programs, because it can
    be rather difficult just to find the function you need, you're
    tempted to use it right there, just to see if it works, and leave
    cleaning up for later, which never comes; 

    gui frameworks are worse than the io monad; try to abstract 
    and limit your uses of gui lib features to as few modules as 
    possible; nicer code, easier to switch to different framework

- abi incompatibility!!^*L"$W&%*^"%*! 

    sorry,-) but that has become the deal breaker for me; it is
    bad enough that there are two major haskell gui libs out
    there, as it means that your clients may have the wrong one
    or none at all, and need to install the one you need; but,
    worse than that, whenever there's a new ghc release, 
    everybody needs to rebuild their gui libs, and if you
    have the latest ghc release and a recent ghc head installed,
    you even need separate copies of the gui lib, etc, etc. 

    so you use a nice high-level language to get a lot done
    in very little very portable code, but instead of distributing
    a few pages of haskell, with build as simple as ghc --make,
    you have to worry about rather huge gui lib installations,
    and you have to worry anew for each ghc release..

btw, i am thinking about reviving my hcpn project, to make 
use of the ghc api, but i'd like to get rid of the binary gui lib 
dependency first. my current take on this is "gui lib? no, 
thanks, i'm just  browsing", if you know what i mean?-)


More information about the Haskell-Cafe mailing list