Difference between revisions of "Language extensions"

From HaskellWiki
Jump to navigation Jump to search
(Started listing the different language extensions with a short description.)
 
 
(18 intermediate revisions by 3 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/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 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]]
  +
* Derive:
* [[Generics|DeriveGeneric]]
 
  +
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#deriving-typeable-instances DeriveDataTypeable]
  +
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveGeneric DeriveGeneric]
  +
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveFunctor DeriveFunctor]
  +
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveFoldable DeriveFoldable]
  +
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-DeriveTraversable DeriveTraversable]
  +
** [https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/glasgow_exts.html#extension-GeneralizedNewtypeDeriving GeneralizedNewtypeDeriving]
  +
* [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 19: Line 32:
 
* [[GADT]]s : Generalised algebraic datatypes - A more general approach to algebraic datatypes.
 
* [[GADT]]s : Generalised algebraic datatypes - A more general approach to algebraic datatypes.
 
* [[Implicit parameters|ImplicitParams]]
 
* [[Implicit parameters|ImplicitParams]]
  +
* [[KindSignatures]]
 
* [[Multi-parameter type class|MultiParamTypeClasses]] : Enable multiple type parameters in type classes.
 
* [[Multi-parameter type class|MultiParamTypeClasses]] : Enable multiple type parameters in type classes.
  +
* [[Monomorphism restriction|NoMonomorphismRestriction]]
 
* [[Overlapping instance|OverlappingInstances]]
 
* [[Overlapping instance|OverlappingInstances]]
 
* [[Rank-N types|Rank2Types]]
 
* [[Rank-N types|Rank2Types]]
 
* [[Rank-N types|RankNTypes]]
 
* [[Rank-N types|RankNTypes]]
  +
* [[Scoped type variables|ScopedTypeVariables]]
  +
* [[GHC/Stand-alone_deriving_declarations|StandaloneDeriving]]
 
* [[Template Haskell|TemplateHaskell]]
 
* [[Template Haskell|TemplateHaskell]]
  +
* {{GHCUsersGuide|exts/tuple_sections||section on TupleSections}} It allows tuples to be partially applied.
  +
* [[GHC/Type families|TypeFamilies]]
 
* [[Undecidable instance|UndecidableInstances]]
 
* [[Undecidable instance|UndecidableInstances]]
  +
* [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]]
   
   

Latest revision as of 05:36, 9 September 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