A Haskell foreign function interface

Sigbjorn Finne, Sven Panne, Manuel Chakravarty, Malcolm Wallace, and The GHC Team

May 2000


1. Introduction

The motivation behind this foreign function interface (FFI) specification is to make it possible to describe in Haskell source code the interface to foreign functionality in a Haskell system independent manner. It builds on experiences made with the previous foreign function interfaces provided by GHC and Hugs. However, the FFI specified in this document is not in the market of trying to completely bridge the gap between the actual type of an external function, and what is a convenient type for that function to the Haskell programmer. That is the domain of tools like HaskellDirect or Green Card, both of which are capable of generating Haskell code that uses this FFI.

In the following, we will discuss the language extensions of the FFI. The extensions can be split up into two complementary halves; one half that provides Haskell constructs for importing foreign functionality into Haskell, the other which lets you expose Haskell functions to the outside world. We start with the former, how to import external functionality into Haskell.