| GreenCard: A Haskell FFI Preprocessor |
Green Card is a foreign function interface preprocessor for Haskell, simplifying the task of interfacing Haskell programs to external libraries (which are normally exposed via C interfaces).
To interface to an external function using Green Card, you write a small procedure specification. The specification tells Green Card what (Haskell) type you want to give the function together with details of how the arguments (and results) to the Haskell function should be marshalled to and from the data representation used by the external function. Green Card will then generate gobs of low-level boilerplate code that takes care of all the details.
For example, to access the C function OrderSoup(), you'll write the following Green Card spec:
%fun orderSoup :: Kind -> IO Soup
%call (kind arg1)
%code SOUP res1 = OrderSoup(arg1);
%fail { res1 == nullSoup } { ErrorString("No soup for you.") }
%result ( soup {res1})
Green Card will from this generate a Haskell function with the above signature.
A reasonably short specification, but in the majority of cases Green Card
is capable of automatically filling in most fields of a procedure
specification. For OrderSoup(), the following spec would do
%fun OrderSoup :: Kind -> IO Soup
%fail { res1 == nullSoup } { ErrorString("No soup for you.") }
Using the Haskell type signature as a basis, Green Card fills
in the missing %call, %code and %result fields.
Green Card is currently able to generate code compatible with the Glasgow Haskell Compiler, Hugs and (quite possibly) nhc98.
The current version of GreenCard is 3.03 (released April 2009). It has been updated to work with Haskell compilers that support the foreign function interface and hierarchial libraries, and packaged up as a Cabal package.
The major changes from the 2.x series of GreenCard are:
For those needing absolute compatibility with the 2.x series, the previous release (version 2.05) is still available (see below.)
GreenCard 3.03 (released April 2009):
GreenCard 3.01 (released June 2003):
GreenCard 2.05 (released Jan 2003):If you've written some Green Card stubs that you think would be of general interest to other users, please let us know, and we'll be more than happy to add a link to your code.
GreenCard is released under a BSD-style license. This means that you can basically do anything you want with the program.
Foreign Function Interface Resources:
Please send bug reports and feedback to Alastair Reid(alastair at reid-consulting-uk.ltd.uk) or to Sigbjorn Finne (sof at galois.com)