In the following, all formal grammatical definitions are based on the same notation as that defined in the Haskell 98 Report [7, Section 2.1] and we make free use of all nonterminals defined in the Haskell 98 Report. The only addition to the lexical structure of Haskell 98 [7, Section 2] is a single new reserved identifier (namely, foreign) and a set of special identifiers. The latter have a special meaning only within foreign declarations, but may be used as ordinary identifiers elsewhere.
The following productions are added:
| reservedid | ![]() | foreign |
| specialid | ![]() | export | safe | unsafe | ccall |
| | | cplusplus | dotnet | jvm | stdcall | |
| | | system-specific calling conventions | |
The special identifiers ccall, cplusplus, dotnet, jvm, and stdcall are defined to denote calling conventions. However, a concrete implementation of the FFI is free to support additional, system-specific calling conventions whose name is not explicitly listed here.
To refer to objects of an external C context, we introduce the following phrases:
| chname | ![]() | {chchar} . h | (C header filename) |
| cid | ![]() | letter {letter | ascDigit} | (C identifier) |
| chchar | ![]() | letter | ascSymbol<&> | |
| letter | ![]() | ascSmall | ascLarge | _ | |
The range of lexemes that are admissible for chname is a subset of those permitted as arguments to the #include directive in C. In particular, a file name chname must end in the suffix .h. The lexemes produced by cid coincide with those allowed as C identifiers, as specified in [4].