6.1.1. Controlling extensions¶
Language extensions can be controlled (i.e. allowed or not) in two ways:
Every language extension can be switched on by a command-line flag “
-X...
” (e.g.-XTemplateHaskell
), and switched off by the flag “-XNo...
”; (e.g.-XNoTemplateHaskell
).Language extensions can also be enabled using the
LANGUAGE
pragma, thus{-# LANGUAGE TemplateHaskell #-}
(see LANGUAGE pragma).
-
GHC2021
¶ GHC blesses a number of extensions, beyond Haskell 2010, to be suitable to turned on by default. These extensions are considered to be stable and conservative.
GHC2021
is used by GHC if neitherHaskell98
norHaskell2010
is turned on explicitly. Since later versions of GHC may use a laterGHC20xx
by default, users are advised to declare the language set explicitly with-XGHC2021
.Note that, because GHC2021 includes a number of non-standardized extensions, the stability guarantees it provides are not quite as strong as those provided by, e.g.,
Haskell2010
. While GHC does take pains to avoid changing the semantics of these extensions, changes may still happen (e.g. the simplified subsumption change introduced in GHC 9.0 which caused GHC to reject some programs usingRankNTypes
).The
GHC2021
language set comprises the following extensions:BangPatterns
BinaryLiterals
ConstrainedClassMethods
ConstraintKinds
DeriveDataTypeable
DeriveFoldable
DeriveFunctor
DeriveGeneric
DeriveLift
DeriveTraversable
DoAndIfThenElse
EmptyCase
EmptyDataDecls
EmptyDataDeriving
ExistentialQuantification
ExplicitForAll
FieldSelectors
FlexibleContexts
FlexibleInstances
ForeignFunctionInterface
GADTSyntax
GeneralisedNewtypeDeriving
HexFloatLiterals
ImplicitPrelude
ImportQualifiedPost
InstanceSigs
KindSignatures
MonomorphismRestriction
MultiParamTypeClasses
NamedFieldPuns
NamedWildCards
NumericUnderscores
PatternGuards
PolyKinds
PostfixOperators
RankNTypes
RelaxedPolyRec
ScopedTypeVariables
StandaloneDeriving
StandaloneKindSignatures
StarIsType
TraditionalRecordSyntax
TupleSections
TypeApplications
TypeOperators
TypeSynonymInstances
-
Haskell2010
¶ Compile Haskell 2010 language variant. Enables the following language extensions:
CUSKs
DatatypeContexts
DoAndIfThenElse
EmptyDataDecls
FieldSelectors
ForeignFunctionInterface
ImplicitPrelude
MonomorphismRestriction
PatternGuards
RelaxedPolyRec
StarIsType
TraditionalRecordSyntax
-
Haskell98
¶ Compile using Haskell 98 language variant. Enables the following language extensions:
CUSKs
DatatypeContexts
FieldSelectors
ImplicitPrelude
MonomorphismRestriction
NPlusKPatterns
NondecreasingIndentation
StarIsType
TraditionalRecordSyntax
Although not recommended, the deprecated -fglasgow-exts
flag enables
a large swath of the extensions supported by GHC at once.
-
-fglasgow-exts
¶ The flag
-fglasgow-exts
is equivalent to enabling the following extensions:ConstrainedClassMethods
DeriveDataTypeable
DeriveFoldable
DeriveFunctor
DeriveGeneric
DeriveTraversable
EmptyDataDecls
ExistentialQuantification
ExplicitNamespaces
FlexibleContexts
FlexibleInstances
ForeignFunctionInterface
FunctionalDependencies
GeneralizedNewtypeDeriving
ImplicitParams
InterruptibleFFI
KindSignatures
LiberalTypeSynonyms
MagicHash
MultiParamTypeClasses
ParallelListComp
PatternGuards
PostfixOperators
RankNTypes
RecursiveDo
ScopedTypeVariables
StandaloneDeriving
TypeOperators
TypeSynonymInstances
UnboxedTuples
UnicodeSyntax
UnliftedFFITypes
Enabling these options is the only effect of
-fglasgow-exts
. We are trying to move away from this portmanteau flag, and towards enabling features individually.