The Foreign Function Interface (FFI) consists of three parts:
foreign import and export declarations (defined in an extra document A Haskell Foreign Function Interface),
a low-level marshalling library (see Section 4.13, Section 4.27, Section 4.1, Section 4.10, Section 4.24, Section 4.25, Section 4.5, and Section 4.6), and
a high-level marshalling library (this is still under development and not included in the current distribution).
The module Foreign provides the interface to the language independent portion of the second component, i.e., the modules Int (Section 4.13), Word (Section 4.27), Addr (Section 4.1), ForeignObj (Section 4.10), StablePtr (Section 4.24), and Storable (Section 4.25). The two modules CTypes (Section 4.5) and CTypesISO (Section 4.6) are specific to code interfacing with C - especially, for implementing portable Haskell bindings to C libraries. However, currently there is no dedicated support for languages other than C, so that Foreign will usually be used in conjunction with CTypes and CTypesISO.
The code for marshalling of Haskell structures into a foreign representation and vice versa can generally be implemented in either Haskell or the foreign language. At least if the foreign language is a significantly lower level language, such as C, there are good reasons for doing the marshalling in Haskell:
Haskell's lazy evaluation strategy would require any foreign code that attempts to access Haskell structures to force the evaluation of the structures before accessing them. This would lead to complicated code in the foreign language, but does not need any extra consideration when coding the marshalling in Haskell.
Despite the fact that marshalling code in Haskell tends to look like C in Haskell syntax, the strong type system still catches many errors that would otherwise lead to difficult to debug runtime faults.
Direct access to Haskell heap structures from a language like C - especially, when marshalling from C to Haskell, i.e., when Haskell structures are created - carries the risk of corrupting the heap, which usually leads to faults that are very hard to debug. (Paradox as it may seem, the cause for corrupted C structures is usually easier to locate, at least when a conventional debugger like gdb is at hand.)
Consequently, the Haskell FFI emphasises Haskell-side marshalling.