Home

December Surprise Topic: Haskell FFI

Posted on 2009-01-12 by Curt Sampson :: comments enabled

The December 18th meeting, despite being near Christmas and a week earlier than the usual date, was surprisingly well-attended. We had close to a dozen people show up.

I had said that I would do a presentation on Haskell community resources, but ended up not having time to put that together (simple as you’d think it is) due to being plunged into a Haskell FFI project that I really needed to get finished. It turned out to be one of the more interesting things I’d done in Haskell, and it made interfacing with a Microsoft C API under Windows actually enjoyable, if you can believe that! (It’s an interface into the DDEML API, and we’ll be putting it up on Hackage at some point.)

So, since I’d been immersed in it for a solid week, anwyay, I thought perhaps it would be interesting for an impromptu presentation. It went over quite well, in large part I’m sure because the FFI is incredibly well designed.

In my case, I was dealing with Microsoft “stdcall” calling conventions instead of the usual C ones, I had Haskell functions I was passing in as callbacks to be called from the Microsoft library, and I had a main program that had to deal with the whole Windows event-driven thing. It was entirely done in Haskell, with the necessary glue generated by some FFI and hsc2hs directives: there was not a single line of C. (This is quite different from writing something like this for Ruby, where you do a lot of talking to the Ruby interpreter through C functions.) Beyond that, being able to write C-like code that was checked by the Haskell type system made my life a lot easier. Who would have thought something like this could turn out to be so pleasurable?

Everybody was suitably impressed.

There are no slides, but I do have a few links to FFI information, for anybody who’d like to follow up a little further:

The next meeting will be on January 29th, with a topic to be determined.

Add a comment »
comments are moderated