A foreign-language interface provides a way for software written in a one language to interact with code written in another. Programming languages that lack foreign-language interfaces die a lingering death.
All Haskell implementations known to us do provide facilities for
interfacing to external functionality. For instance, the Glasgow
Haskell compiler (GHC) provides a ccall
construct for mixing
calls to C functions with standard Haskell code performing
I/O. However, the mechanism is low-level and it often requires the
programmer to write lots of tedious boilerplate code to convert
Haskell values into the representations expected by the external
function.
We present here Green Card, a preprocessor for Haskell that tries to simplify the task of defining an interface/binding to foreign functionality.
Our goals are limited. We do not set out to solve the problem of language interoperation and foreign-language interfaces in general; rather, we intend to profit from the work of others' in this area. Specifically, we aim to provide a convenient way to call C procedures from Haskell.
The ability to call C from Haskell is an essential foundation. Through it we can access operating system services and mountains of other software libraries. It also provides a basis on which to tackle the problem of writing and accessing software components from Haskell.
In the other direction, should we be able to write a Haskell library that a C program can use? In principle this makes sense, but in practice there is little demand for it. The exception is the ability to support some sort of Haskell callbacks, but that is a very limited form of C calling Haskell.
Should we support languages other than C? The trite answer is that pretty much everything available as a library is available as a C library. For other languages the right thing to do is to interface to a language-independent software component architecture, rather than to a raft of specific languages. There's a couple of such architectures to choose from; COM and CORBA. This document, however, describes only the C interface mechanism.