Wanted: a small, portable, useful C library
May 12th, 2008 by Bryan O'Sullivan
Update 2008-05-12: We’ve decided to go with PCRE. Thanks for all of your suggestions!
We’re about to start on one of our last chapters, on using Haskell’s foreign function interface (FFI). We’re currently kicking around candidate C libraries that we can use as examples to write bindings for.
So far, we’ve thought about PCRE and sqlite: each is small, widely used, and portable to Linux, OS X, and Windows. On the slightly negative side, there already exist Haskell bindings for each (in fact, PCRE has three different libraries with bindings to it).
If you’d like to suggest some other library that meets the criteria of a small API, an open source license, portability to the three major platforms, and general niftiness, please leave us a comment with your idea. Thanks!
I’d like to see a fairly functional binding to one of the embeddable scheme interpreters. While I know many think Haskell is the end-all-be-all and ask “why would you want scheme in haskell?” I like to use scheme as a scripting/configuration/plugin language for applications.
I’m not sure how complex the API is on any of the embeddable scheme engines, but maybe something simple to get a basic scheme engine running would be cool.
I know Guile is one interpreter designed specifically with embeddability in mind and I’m told its fairly simple to do so.
libxml is open source, extremely widely used, useful, and x-platform but probably fails your definition of “small.” That said, Haskell could really use a binding…
I`d like to see some “reverse” binding examples, where Haskell interpreter is embedded in some other application, as extension/scripting facility. But I don`t know is it even possible
What about aspell for spell checking? I have never worked with the C API, but it probably isn’t that complicated.
http://aspell.net/
What about syck?
http://code.whytheluckystiff.net/syck
How about expat? I believe there’s already a haskell wrapper for it, but I think it will make a good example in book like RWH
The link is http://sourceforge.net/projects/expat/
google for something using python and ctypes - half the work done! ^^ maybe take on a small-ish subset of sdl+opengl? or tinyxml? devil for simple image processing? libtorrent for downloading linux isos? (ocaml has mldonkey, right?)
I did the Expat wrapper. I agree it’d be a good library to demonstrate for a book. Its API is very simple but also C-like, so I did a number of revisions (starting with a straightforward literal port) that improved performance and usefulness (using records, using ByteStrings, etc.).
GLFW + GLEW maybe for opengl support (smaller than sdl for that task). PortAudio for sound generation/mixing.
That’s what I’m using from C/C++ or whatever language I feel like binding to =)
Constraint solvers often come in handy. So I’ll fire in MiniSat as a random suggestion!
http://minisat.se/
Small, but perhaps not widely used. It does have the advantage of being easy to understand, for the reader and the implementor.
I’ve thought of trying it myself, but haven’t got round to it.
Matt.
The CUPS API (for printing) isn’t that big, but that would only be useful on Linux and Mac.
What about curl? Really nice, cool and small http lib
What about FFTW? This is a library for doinf Fourier transformations on n-dimensional data and is used almost everywhere when it comes to signal/image processing. This would also be a nice example on how to deal with (multidimensional) arrays/large datasets in haskell.
http://www.fftw.org/
What about PortAudio?
http://www.portaudio.com/
I was thinking of doing this myself actually, I just never got around to it.
http://portaudio.com/docs/v19-doxydocs/portaudio_8h.html
That is the full PortAudio API.
Unfortunately I have little experience with the raw FFI - for something like this (many enumerations and structs and whatnot,) it might be a lot more work than you’re willing to invest. Seems to be more suited for c2hs.
Go for Open Dynamics Engine : http://www.ode.org/
Quote from website:
ODE is an open source, high performance library for simulating rigid body dynamics.
It is used in: http://www.ode.org/users.html
Perhaps SDL? This is Mac, Linux and Win32 friendly, and provides a basic framework for graphics, joystick input and sound, amongst others.
I’ve worked on open source bindings of this library for Common Lisp, and it seems to fit your requirements.
I’d like to put in a vote for id3v2, the mp3 tag library. Everyone wants to write a tag editor…
http://www.tildeslash.com/libzdb/
http://www.spread.org/
Hmm, spread is already done. Sorry about that.
http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hspread-0.3
I second on curl.
The reason is that curl really is *useful* for everyday tasks too.
I have yet to find a good Haskell binding for OpenSSL. It should portable to all the platforms you mentioned, and it’s API is reasonably small, though it’s possible it may be too large for your uses.
If it is too large, I’d say the suggestion to do curl is probably a good one.
ImageMagick? Probably too big to do the whole thing, but you could do a representative sample.
SDL would be my choice. People tend to like visual examples.
ImageMagick was a good idea. Useful, too.
Depends on what is considered small, but a good Tcl/Tk binding would be nice and it is in the useful and small (compared to many other UI toolkits like gtk or qt) category.
How about libdbus?