Next
Previous
Contents
The basic way in which almost any foreign language interface works is
this. The signature of each foreign-language procedure is expressed
in some formal notation. From this signature, stub code is generated
that marshals the parameters ``across the border'' between the
two languages, calls the procedure using the foreign language's
calling convention, and then unmarshals the results back across the
border. Dealing with the different calling convetions of the two
languages is usually the easy bit. The complications come in the
marshaling of parameters, where data valuesed built by one language is
transformed into a form that is comprehensible to the other.
A major design decision is the choice of notation in which to describe
the signatures of the procedures that are to be called across the
interface. There are three main possibilities:
- Use the host language (Haskell, in our case). That is,
give the foreign function a Haskell type signature, and generate the
stub code from it. Green Card uses this approach, as does J/Direct
(Microsoft's foreign-language interface for Java).
- Use the foreign language (say C). In this case the
stub code must be generated from the C prototype for the
procedure. SWIG uses this approach.
- Use a separate Interface Definition Language (IDL),
designed specifically for the purpose.
For H/Direct, we opt for the use of IDL as the notation to describe
foreign-language interfaces (see the H/Direct ICFP paper for the
motivations behind this choice.) Specifically, H/Direct uses IDL to
help the programmer solve the following four tasks:
- Calling foreign procedures from Haskell. By describing
the signatures of the foreign procedures using IDL, H/Direct generates
Haskell stubs that correctly invokes these foreign procedures.
- Calling Haskell from the outside world. The dual to
previous. By giving Haskell functions IDL signatures,
H/Direct generates stubs that allows you to call Haskell functions
from C.
- Calling COM components from Haskell. IDL is the de
facto standard for textually describing the functionality
supported by COM components. H/Direct translates the specification of
a COM component into a set of Haskell stubs that allows you to create
and use COM components from within Haskell.
- Implementing COM components in Haskell. H/Direct also
uses IDL to guide the generation of stubs that takes care of all the
details involved in exposing Haskell code as a COM component.
This document presents the programmer view of how H/Direct supports
these four different uses of IDL, followed by a section that presents
the design and implementation of the layers of stub code that H/Direct
generates when given an IDL specification.
Next
Previous
Contents