[Haskell-cafe] ANN: bindings-SDL 1.0.2,
the domain specific language for FFI description
mauricio.antunes at gmail.com
Mon Nov 16 06:17:37 EST 2009
This package is to be used with hsc2hs. (hsc2hs is called
automatically if you use Cabal.) It's a self-contained set of
macros used to create a Haskell wrap for a C interface. They
follow the idea that it's better to have a C-like wrap code
first and then write Haskell-like code on top of that than going
directly from C to Haskell style.
Hackage link: http://hackage.haskell.org/package/bindings-DSL
Wiki documentation: http://bitbucket.org/mauricio/bindings-dsl
The fancy 'domain specific language' comes from 'binding-SDL'
macros hability to describe a C interface. Instead of writing
Haskell or preprocessor code, you can use 'bindings-DSL' macros
to describe the interface you want to wrap without knowledge of
how that description translates to preprocessor or Haskell code.
Suppose, for instance, you have the following C struct:
struct example_struct *p;
It will be described like this:
#starttype struct example_struct
#field n , CInt
#field p , Ptr <example_struct>
and this gives you a Haskell data type (automatically named
C'example_struct) with the same fields and Storable instantiation.
Here is a bigger example, with structs, macros, functions and
global variables. Suppose you want to wrap this:
Then this is how your 'bindings-DSL' code will look like:
That code translates to these Haskell declarations:
'bindings-DSL' came from previous 'bindings-common' package. It
started as an effort to have many Haskell interfaces to good
libraries available on Hackage, and came to be a language to
support writing such interfaces easily and reliably.
Hope it's usefull to you.
More information about the Haskell-Cafe