[cairo] reworked haskell bindings

Abraham Egnor aegnor at antioch-college.edu
Sat Mar 20 16:06:52 PST 2004

Much to my shame, the haskell bindings have been lagging far behind the
current state of cairo.  Well, no more!  In an enormous stroke of luck, my
employer (Aetion Technologies LLC, www.aetion.com) has need of a good
haskell vector graphics library, so I've been paid to bring the bindings
back up to par.  In the process, I've done a bunch of things I was meaning
to do - rework the structure so it's easier for me to maintain, and add a
few tasty features.  The most interesting of said features is that instead
of using my simple little cobbled-together event loop for animation, it
now uses Yampa (www.haskell.org/yampa), which (a) is much more functional
in flavor and (b) allows for all kinds of interesting constructions:

mul :: Double -> SF Input Double
mul d = proc rin ->
    do rec q <- onKey Press "q" -< rin
           w <- onKey Press "w" -< rin
           let e = merge (q `tag` 0.5) (w `tag` 2.0)
           m <- drSwitch (constant d) -< (rin, fmap (\v -> constant $ m *
v) e)
       returnA -< m

This function handles keeping track of a multiplier value that can be
halved by pressing "q" and doubled by pressing "w".  I find a few things
noteworthy about this function.  First is that the input events that
trigger the action are directly tied to the action, i.e. there's no
central event loop.  Second is that instead of explicitly keeping around
the state (in this case, the value of "m"), it is simply recursively
defined in terms of itself.

Okay, enough evangelism :)  The hscairo page
(http://www.cairographics.org/hscairo) has been updated to have correct
download information.


More information about the cairo mailing list