The Haskell 98 Foreign Function Interface 1.0
An Addendum to the Haskell 98 Report

Manuel Chakravarty [editor], University of New South Wales
Sigbjorn Finne, Galois Connections, Inc.
Fergus Henderson, University of Melbourne
Marcin Kowalczyk, Warsaw University
Daan Leijen, University of Utrecht
Simon Marlow, Microsoft Research, Cambridge
Erik Meijer, Microsoft Corporation
Sven Panne, BetaResearch GmbH
Simon Peyton Jones, Microsoft Research, Cambridge
Alastair Reid, Reid Consulting (UK) Ltd.
Malcolm Wallace, University of York
Michael Weber, University of Aachen

Copyright (c) [2002..2003] Manuel M. T. Chakravarty

The authors intend this Report to belong to the entire Haskell community, and so we grant permission to copy and distribute it for any purpose, provided that it is reproduced in its entirety, including this Notice. Modified versions of this Report may also be copied and distributed for any purpose, provided that the modified version is clearly presented as such, and that it does not claim to be a definition of the Haskell 98 Foreign Function Interface.

The master version of the Haskell FFI Report is at haskell.org. Any corrections or changes in the report are found there.

Contents
Preface
 Acknowledgements
1 Introduction
 1.1 Embedding Into Haskell 98
 1.2 Language-Specific FFI Support
 1.3 Contexts
 1.4 Cross Language Type Consistency
2 Lexical Structure
3 Foreign Declarations
 3.1 Calling Conventions
 3.2 Foreign Types
 3.3 Import Declarations
 3.4 Export Declarations
4 Specification of External Entities
 4.1 Standard C Calls
 4.2 Win32 API Calls
5 Marshalling
 5.1 Foreign
 5.2 Bits
 5.3 Int and Word
 5.4 Ptr
 5.5 ForeignPtr
 5.6 StablePtr
 5.7 Storable
 5.8 MarshalAlloc
 5.9 MarshalArray
 5.10 MarshalError
 5.11 MarshalUtils
6 C-Specific Marshalling
 6.1 CForeign
 6.2 CTypes
 6.3 CString
 6.4 CError
References