Difference between revisions of "Language extensions"
Jump to navigation
Jump to search
(fix link to tuple sections) |
|||
(7 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] |
+ | 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 18: | Line 24: | ||
** [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 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#deriving-typeable DeriveTraversable] |
||
+ | ** [http://www.haskell.org/ghc/docs/latest/html/users_guide/deriving.html#id616911 GeneralizedNewtypeDeriving] |
||
+ | * [https://downloads.haskell.org/ghc/latest/docs/html/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 32: | Line 40: | ||
* [[Scoped type variables|ScopedTypeVariables]] |
* [[Scoped type variables|ScopedTypeVariables]] |
||
* [[Template Haskell|TemplateHaskell]] |
* [[Template Haskell|TemplateHaskell]] |
||
− | * [ |
+ | * [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] |
* [http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#view-patterns ViewPatterns] |
||
+ | * [[QualifiedDo]] |
||
+ | |||
+ | = See also = |
||
+ | |||
+ | * [[Use of language extensions]] |
||
Revision as of 06:01, 23 July 2020
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.
- DatatypeContexts : Add type constraints to your datatype.
- DefaultSignatures
- Derive:
- DuplicateRecordFields (GHC 8.0.1+) : Allow definition of record types with identically-named fields.
- ExistentialQuantification
- FlexibleContexts
- FlexibleInstances : Allow a type parameter to occure twice within a type class instance.
- FunctionalDependencies : Are used to constrain the parameters of type classes.
- GADTs : Generalised algebraic datatypes - A more general approach to algebraic datatypes.
- ImplicitParams
- KindSignatures
- MultiParamTypeClasses : Enable multiple type parameters in type classes.
- NoMonomorphismRestriction
- OverlappingInstances
- Rank2Types
- RankNTypes
- ScopedTypeVariables
- TemplateHaskell
- TupleSections : Allow tuples to be partially applied.
- TypeFamilies
- UndecidableInstances
- ViewPatterns
- QualifiedDo