|Version 3 (modified by ross@…, 8 years ago) (diff)|
Foreign Function Interface
Adds support for invoking code written in other programming languages from Haskell and vice versa. The FFI is designed as a non-intrusive extension to the Haskell 98 standard.
- Widely accepted and used addendum.
- Provides an essential facility.
- Inaccurate foreign imports can invalidate all guarantees given by Haskell.
- Some feel that the inclusion of unsafePerformIO sends the wrong signal.
- It is true that by giving inaccurate foreign imports one can define unsafePerformIO, but that doesn't mean it should be standard.
- The stated purpose of unsafePerformIO in the FFI (hiding marshalling and unmarshalling for otherwise pure functions) can be achieved with a runST-like device if the language has Rank2Types or RankNTypes.
- Foreign imports may specify a single include file. This is sufficient in theory, but most GHC users prefer to use -#include options instead, and the standard form is poorly supported by GHC. The hierarchical libraries use an INCLUDE pragma as a portable replacement for OPTIONS_GHC -#include.
- Cross-platform libraries (e.g. HOpenGL) often want to import the same foreign functions using the ccall convention on Unix and the stdcall convention on Windows. The usual method is to use CPP hackery.
- The specified CString conversions are not yet supported in the hierarchical libraries.