[Haskell-cafe] [ANNOUNCE] Bindings for libguestfs

Richard W.M. Jones rjones at redhat.com
Wed May 13 06:40:07 EDT 2009

On Tue, May 12, 2009 at 03:11:32PM -0400, John Dorsey wrote:
> Richard,
> > I added some partial bindings for libguestfs[1] here:
> > http://git.et.redhat.com/?p=libguestfs.git;a=blob;f=haskell/Guestfs.hs;hb=HEAD
> Terrific!  Partial bindings are great.  Thanks for releasing it.  I haven't
> taken the time to look at your code, but...
> > BTW, I found the documentation on writing FFIs very contradictory and
> > incomplete.  For example, I was completely defeated trying to find
> > ways to do simple stuff like passing in integers or returning
> > booleans.  *Potentially* Haskell's FFI seems like it might be one of
> > the best out of the languages I've used so far, but it needs way more
> > documentation and examples.
> Can you be more specific about what needs improvement?
> I wrote a partial Haskell binding for Net-SNMP recently, and I got along
> pretty well using the API docs at
> http://www.haskell.org/ghc/docs/latest/html/libraries/index.html, and an
> example in RWH using hsc2hs.

I guess it's easier if one is more used to Haskell (see my .sig)

> What did you see that was contradictory?

Specific things would be:

Recommendation to use 'throwDyn' to throw exceptions, yet this
function doesn't exist in my version of GHC.  In fact, none of the
code here:


works in GHC at all, as far as I could tell.

No good examples available on how to use ForeignPtr.  Yet I'd argue
that almost any non-trivial modern C library bindings will have some
concept of an opaque object, so this is the most vital example.  (The
examples in RWH ch 17 weren't enough for me).

I'd really like to know what parameters and return types are
permissible for 'foreign import ccall' statements.  By trial and error
I found out.

How do I convert to/from booleans?

How do I really use C structures?  Real examples, please.

How can I free a C string that is returned from a 'caller frees' C
function?  Does Foreign.Marshall.Alloc.free work for this?

Again, reflecting my own inexperience with Haskell, I found
'withCString', 'maybeWith', 'withMany', 'withArray0' etc to be both
undocumented and extremely confusing to use.

How do I specify a 64 bit int?  Using 'Int64#' just causes syntax

What's a good emacs editing mode for Haskell code?  My emacs thinks
Haskell code is LISP ...


Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 75 OCaml packages (the OPEN alternative to F#)

More information about the Haskell-Cafe mailing list