Difference between revisions of "Language Pragmas"

From HaskellWiki
Jump to: navigation, search
m (Use <code> instead of <haskell> for command line example)
(Update chapter number and link to GHC Users Guide)
 
Line 33: Line 33:
 
</haskell>
 
</haskell>
   
A detailed explanation of the language extensions supported by [[GHC]] and the language pragmas that enable them is in [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html chapter 7 of the GHC User's Guide].
+
A detailed explanation of the language extensions supported by [[GHC]] and the language pragmas that enable them is in [http://www.haskell.org/ghc/docs/latest/html/users_guide/lang.html chapter 10 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:
 
You can obtain a list of the language pragmas supported by a specific installed version of [[GHC]] by running the command:

Latest revision as of 01:46, 10 December 2020

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 10 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