Personal tools

Language Pragmas

From HaskellWiki

Jump to: navigation, search

A language pragma directs the Haskell compiler to enable an extension or modification of the Haskell language. Language pragmas are defined in section 12.3 of Haskell 2010 Report.

Language pragmas in a Haskell module must appear at the very beginning of the module. Language pragmas can be preceded or followed by comments and whitespace, but they must precede any other Haskell code in the module. An example of language pragmas in a module:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

Language pragmas can be combined into a comma-separated list:

{-# LANGUAGE OverloadedStrings, TemplateHaskell #-}

Language pragams can be specified for an entire project using the "extensions" field in the Cabal file:

extensions: OverloadedStrings, TemplateHaskell

For the GHC compiler, language pragmas can also be specified using the "-X" flag, either for the "ghc" command:

ghc -XOverloadedStrings ...

or in GHCi using the ":set" command:

Prelude> :set -XOverloadedStrings

A detailed explanation of the language extensions supported by GHC and the language pragmas that enable them is in chapter 7 of the GHC User's Guide.

You can obtain a list of the language pragmas supported by a specific installed version of GHC by running the command:

ghc --supported-extensions