Google

NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.64 ">

Chapter 8. Foreign function interface (FFI)

GHC (mostly) conforms to the Haskell 98 Foreign Function Interface Addendum 1.0, whose definition is available from http://haskell.org/. The FFI support in GHC diverges from the Addendum in the following ways:

  • The routines hs_init(), hs_exit(), and hs_set_argv() from Chapter 6.1 of the Addendum are not supported yet.

  • Syntactic forms and library functions proposed in earlier versions of the FFI are still supported for backwards compatibility.

  • GHC implements a number of GHC-specific extensions to the FFI Addendum. These extensions are described in Section 8.1, but please note that programs using these features are not portable. Hence, these features should be avoided where possible.

The FFI libraries are documented in the accompanying library documentation; see for example the Foreign module.

8.1. GHC extensions to the FFI Addendum

The FFI features that are described in this section are specific to GHC. Avoid them where possible to not compromise the portability of the resulting code.

8.1.1. Arrays

The types ByteArray and MutableByteArray may be used as basic foreign types (see FFI Addendum, Section 3.2). In C land, they map to (char *).

8.1.2. Unboxed types

The following unboxed types may be used as basic foreign types (see FFI Addendum, Section 3.2): Int#, Word#, Char#, Float#, Double#, Addr#, StablePtr# a, MutableByteArray#, ForeignObj#, and ByteArray#.