Chapter 7. GHC Language Features

Table of Contents
7.1. Language options
7.2. Unboxed types and primitive operations
7.3. Syntactic extensions
7.4. Type system extensions
7.5. Template Haskell
7.6. Assertions
7.7. Pragmas
7.8. Rewrite rules
7.9. Generic classes
7.10. Concurrent and Parallel Haskell

As with all known Haskell systems, GHC implements some extensions to the language. To use them, you'll need to give a -fglasgow-exts option.

Virtually all of the Glasgow extensions serve to give you access to the underlying facilities with which we implement Haskell. Thus, you can get at the Raw Iron, if you are willing to write some non-standard code at a more primitive level. You need not be “stuck” on performance because of the implementation costs of Haskell's “high-level” features—you can always code “under” them. In an extreme case, you can write all your time-critical code in C, and then just glue it together with Haskell!

Before you get too carried away working at the lowest level (e.g., sloshing MutableByteArray#s around your program), you may wish to check if there are libraries that provide a “Haskellised veneer” over the features you want. The separate libraries documentation describes all the libraries that come with GHC.

7.1. Language options

These flags control what variation of the language are permitted. Leaving out all of them gives you standard Haskell 98.

-fglasgow-exts:

This simultaneously enables all of the extensions to Haskell 98 described in Chapter 7, except where otherwise noted.

-ffi and -fffi:

This option enables the language extension defined in the Haskell 98 Foreign Function Interface Addendum plus deprecated syntax of previous versions of the FFI for backwards compatibility.

-fwith:

This option enables the deprecated with keyword for implicit parameters; it is merely provided for backwards compatibility. It is independent of the -fglasgow-exts flag.

-fno-monomorphism-restriction:

Switch off the Haskell 98 monomorphism restriction. Independent of the -fglasgow-exts flag.

-fallow-overlapping-instances, -fallow-undecidable-instances, -fallow-incoherent-instances, -fcontext-stack

See Section 7.4.5.3. Only relevant if you also use -fglasgow-exts.

-finline-phase

See Section 7.8. Only relevant if you also use -fglasgow-exts.

-fgenerics

See Section 7.9. Independent of -fglasgow-exts.

-fno-implicit-prelude

GHC normally imports Prelude.hi files for you. If you'd rather it didn't, then give it a -fno-implicit-prelude option. The idea is that you can then import a Prelude of your own. (But don't call it Prelude; the Haskell module namespace is flat, and you must not conflict with any Prelude module.)

Even though you have not imported the Prelude, most of the built-in syntax still refers to the built-in Haskell Prelude types and values, as specified by the Haskell Report. For example, the type [Int] still means Prelude.[] Int; tuples continue to refer to the standard Prelude tuples; the translation for list comprehensions continues to use Prelude.map etc.

However, -fno-implicit-prelude does change the handling of certain built-in syntax: see Section 7.3.6.