Subscribe to
Posts
Comments

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!

27 Responses to “Wanted: a small, portable, useful C library”

  1. on 12 May 2008 at 10:05 UTCIsaac

    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.

  2. on 12 May 2008 at 10:06 UTCKeith Fahlgren

    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…

  3. on 12 May 2008 at 10:24 UTCKleschinski

    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 :)

  4. on 12 May 2008 at 10:53 UTCJohn Lenz

    What about aspell for spell checking? I have never worked with the C API, but it probably isn’t that complicated.

    http://aspell.net/

  5. on 12 May 2008 at 11:00 UTCBrett DiFrischia

    What about syck?

    http://code.whytheluckystiff.net/syck

  6. on 12 May 2008 at 11:03 UTCHemanth

    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/

  7. on 12 May 2008 at 11:40 UTCBaczek

    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?)

  8. on 12 May 2008 at 11:44 UTCEvan M

    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.).

  9. on 12 May 2008 at 11:59 UTCvoid

    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 =)

  10. on 12 May 2008 at 12:07 UTCMatthew Naylor

    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.

  11. on 12 May 2008 at 12:11 UTCpdw

    The CUPS API (for printing) isn’t that big, but that would only be useful on Linux and Mac.

  12. on 12 May 2008 at 12:12 UTCvoid

    What about curl? Really nice, cool and small http lib

  13. on 12 May 2008 at 12:49 UTCjj

    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/

  14. on 12 May 2008 at 12:51 UTCAustin Seipp

    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.

  15. on 12 May 2008 at 12:54 UTCAnonymous Coward from /.

    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

  16. on 12 May 2008 at 12:57 UTCJustin Heyes-Jones

    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.

  17. on 12 May 2008 at 13:00 UTCdsf

    I’d like to put in a vote for id3v2, the mp3 tag library. Everyone wants to write a tag editor…

  18. on 12 May 2008 at 13:21 UTCspringande

    http://www.tildeslash.com/libzdb/

  19. on 12 May 2008 at 13:23 UTCGuido Kollerie

    http://www.spread.org/

  20. on 12 May 2008 at 13:28 UTCGuido Kollerie

    Hmm, spread is already done. Sorry about that.

    http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hspread-0.3

  21. on 12 May 2008 at 14:14 UTCshe

    I second on curl.

    The reason is that curl really is *useful* for everyday tasks too.

  22. on 12 May 2008 at 14:39 UTCHezekiah

    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.

  23. on 12 May 2008 at 15:18 UTCpozorvlak

    ImageMagick? Probably too big to do the whole thing, but you could do a representative sample.

  24. on 12 May 2008 at 18:46 UTCIjon Tichy

    SDL would be my choice. People tend to like visual examples.

  25. on 12 May 2008 at 19:55 UTCjj

    ImageMagick was a good idea. Useful, too.

  26. on 13 May 2008 at 06:18 UTCMichael Schlenker

    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.

  27. on 13 May 2008 at 13:08 UTCJeff Read

    How about libdbus?