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 language-independent marshalling library (whose interface is provided by the present module), and
a language-dependent marshalling library (see Section 4.6).
The language-independent portion of the marshalling library, whose entire interface is provided by the module Foreign, consists of the following modules: Int (Section 4.18), Word (Section 4.38), Ptr (Section 4.29), ForeignPtr (Section 4.15), StablePtr (Section 4.34), Storable (Section 4.35), MarshalAlloc (Section 4.22), MarshalArray (Section 4.23), MarshalError (Section 4.24), and MarshalUtils (Section 4.25). The language-dependent portion of the marshalling library is currently only available for the language C, and is essentially intended to support writing portable Haskell bindings to C libraries. All C-dependent functionality can be obtained from the module CForeign (Section 4.6).
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.
As module Foreign simply re-exports the interface of the other modules listed above, please refer to the documentation of these modules for the details of the provided definitions.