Personal tools

Language extensions

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(List of language extensions by name)
(See also)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
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.
 
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 [http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/pragmas.html#language-pragma LANGUAGE pragma] or (in GHC) using the flag -X. The LANGUAGE pragma should be preferred here.
+
They can be enabled using the [http://www.haskell.org/ghc/docs/7.0.4/html/users_guide/pragmas.html#language-pragma LANGUAGE pragma]  
 +
 
 +
<hask>
 +
{-# LANGUAGE <Extension>, <Extension> #-}
 +
</hask>
 +
 
 +
or (in GHC) using [https://downloads.haskell.org/~ghc/master/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 12: Line 18:
 
* [[Datatype contexts|DatatypeContexts]] : Add type constraints to your datatype.
 
* [[Datatype contexts|DatatypeContexts]] : Add type constraints to your datatype.
 
* [[Default signatures|DefaultSignatures]]
 
* [[Default signatures|DefaultSignatures]]
* [[Generics|DeriveGeneric]]
+
* Derive:
 +
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveDataTypeable]
 +
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveGeneric]
 +
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveFunctor]
 +
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveFoldable]
 +
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#deriving-typeable DeriveTraversable]
 +
** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#id616911 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.
 
* [[Existential type|ExistentialQuantification]]
 
* [[Existential type|ExistentialQuantification]]
 
* [[Flexible contexts|FlexibleContexts]]
 
* [[Flexible contexts|FlexibleContexts]]
Line 31: Line 44:
 
* [[Undecidable instance|UndecidableInstances]]
 
* [[Undecidable instance|UndecidableInstances]]
 
* [http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#view-patterns ViewPatterns]
 
* [http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#view-patterns ViewPatterns]
 +
 +
= See also =
 +
 +
* [[Use of language extensions]]
  
  
 
[[Category:Language extensions]]
 
[[Category:Language extensions]]

Latest revision as of 09:17, 14 February 2017

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.

[edit] 1 List of language extensions by name

This list is far from complete and needs extension.

[edit] 2 See also