Difference between revisions of "Language extensions"

From HaskellWiki
Jump to navigation Jump to search
(add pragma example and Duplicate record fields link)
(fix links to ghc user guide)
(6 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
</hask>
 
</hask>
   
or (in GHC) using [https://downloads.haskell.org/~ghc/master/users-guide/lang.html flags] <code>-X<Extension></code>.
+
or (in GHC) using [https://downloads.haskell.org/ghc/latest/docs/html/users_guide/lang.html flags] <code>-X<Extension></code>.
   
 
Before just using the language extension that fits your need, [[Use of language extensions|think about
 
Before just using the language extension that fits your need, [[Use of language extensions|think about
Line 19: Line 19:
 
* [[Default signatures|DefaultSignatures]]
 
* [[Default signatures|DefaultSignatures]]
 
* Derive:
 
* Derive:
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveDataTypeable]
+
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#deriving-typeable-instances DeriveDataTypeable]
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveGeneric]
+
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveGeneric DeriveGeneric]
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveFunctor]
+
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveFunctor DeriveFunctor]
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveFoldable]
+
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveFoldable DeriveFoldable]
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveTraversable]
+
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveTraversable DeriveTraversable]
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#id616911 GeneralizedNewtypeDeriving]
+
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-GeneralizedNewtypeDeriving GeneralizedNewtypeDeriving]
* [https://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#duplicate-record-fields DuplicateRecordFields] (GHC 8.0.1+) : Allow definition of record types with identically-named fields.
+
* [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DuplicateRecordFields DuplicateRecordFields] (GHC 8.0.1+) : Allow definition of record types with identically-named fields.
 
* [[Existential type|ExistentialQuantification]]
 
* [[Existential type|ExistentialQuantification]]
 
* [[Flexible contexts|FlexibleContexts]]
 
* [[Flexible contexts|FlexibleContexts]]
Line 40: Line 40:
 
* [[Scoped type variables|ScopedTypeVariables]]
 
* [[Scoped type variables|ScopedTypeVariables]]
 
* [[Template Haskell|TemplateHaskell]]
 
* [[Template Haskell|TemplateHaskell]]
* [http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#tuple-sections TupleSections] : Allow tuples to be partially applied.
+
* [https://downloads.haskell.org/ghc/latest/docs/html/users_guide/glasgow_exts.html#tuple-sections TupleSections] : Allow tuples to be partially applied.
 
* [[GHC/Type families|TypeFamilies]]
 
* [[GHC/Type families|TypeFamilies]]
 
* [[Undecidable instance|UndecidableInstances]]
 
* [[Undecidable instance|UndecidableInstances]]
* [http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#view-patterns ViewPatterns]
+
* [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-ViewPatterns ViewPatterns]
  +
* [[QualifiedDo]]
  +
  +
= See also =
  +
  +
* [[Use of language extensions]]
   
   

Revision as of 18:45, 3 February 2021

Language extensions are used to enable language features in Haskell that may seem useful in certain cases. They can be used to loosen restrictions in the type system or add completely new language constructs to Haskell.

They can be enabled using the LANGUAGE pragma

{-# LANGUAGE <Extension>, <Extension> #-}

or (in GHC) using flags -X<Extension>.

Before just using the language extension that fits your need, think about when it is useful and what risk it may bring to your program.

List of language extensions by name

This list is far from complete and needs extension.

See also