[Haskell-cafe] Newbie Question: Using Haskell Functions in a C Program

Luke Palmer lrpalmer at gmail.com
Sun May 11 06:25:07 EDT 2008


On Thu, May 8, 2008 at 5:09 PM, Philip Müller <mail at philip.in-aachen.net> wrote:
> Thanks for all the answers. I'm testing this right now and simples cases
> work as expected. However from what I've read it seems it'll get ugly once I
> try to pass a C array to a Haskell function.
>
>  Well, maybe arrays in C have been ugly before trying to pass them to
> Haskell functions ;)
>
>  To elaborate a bit about the C program, it's a small game using OpenGL for
> output and mouse and keyboard for input.

The SDL package
(http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL) is
quite nice for input handling and window making and whatnot.  I have
heard it is a bitch to get working on Windows, though.

The OpenGL package
(http://hackage.haskell.org/cgi-bin/hackage-scripts/package/OpenGL) is
good, but can be a real pain to get going because the documentation
layout is terrible.

To toot my own horn, if your graphics are simple enough (specifically,
2D), you can use graphics-drawingcombinators
(http://hackage.haskell.org/cgi-bin/hackage-scripts/package/graphics-drawingcombinators),
which has a simple interface, for output.  It depends on SDL, so above
caveat applies.

But once you learn the pattern, I/O is basically a transliteration
from C.  The reason I struggle with such C-like libraries in Haskell
is that I spend all my time trying to clean them up and make them more
Haskell-like.   I definitely consider FFI more of a pain (when you
want to do anything sophisticated) than the OpenGL package, though.

Luke


More information about the Haskell-Cafe mailing list