summaryrefslogtreecommitdiff
path: root/docs/users_guide/exts/control.rst
blob: 1a5431f526aa73818e7dea2d500cc2591e78a9ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
.. _options-language:

Controlling extensions
----------------------

.. index::
   single: language; option
   single: options; language
   single: extensions; options controlling

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 :ref:`language-pragma`).

.. extension:: GHC2021
    :shortdesc: Use GHC’s set of default language extensions from 2021

    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 neither ``Haskell98`` nor ``Haskell2010`` is
    turned on explicitly. Since later versions of GHC may use a later
    ``GHC20xx`` 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., :extension:`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 using :extension:`RankNTypes`).

    The ``GHC2021`` language set comprises the following extensions:

    .. hlist::

     * :extension:`BangPatterns`
     * :extension:`BinaryLiterals`
     * :extension:`ConstrainedClassMethods`
     * :extension:`ConstraintKinds`
     * :extension:`DeriveDataTypeable`
     * :extension:`DeriveFoldable`
     * :extension:`DeriveFunctor`
     * :extension:`DeriveGeneric`
     * :extension:`DeriveLift`
     * :extension:`DeriveTraversable`
     * :extension:`DoAndIfThenElse`
     * :extension:`EmptyCase`
     * :extension:`EmptyDataDecls`
     * :extension:`EmptyDataDeriving`
     * :extension:`ExistentialQuantification`
     * :extension:`ExplicitForAll`
     * :extension:`FieldSelectors`
     * :extension:`FlexibleContexts`
     * :extension:`FlexibleInstances`
     * :extension:`ForeignFunctionInterface`
     * :extension:`GADTSyntax`
     * :extension:`GeneralisedNewtypeDeriving`
     * :extension:`HexFloatLiterals`
     * :extension:`ImplicitPrelude`
     * :extension:`ImportQualifiedPost`
     * :extension:`InstanceSigs`
     * :extension:`KindSignatures`
     * :extension:`MonomorphismRestriction`
     * :extension:`MultiParamTypeClasses`
     * :extension:`NamedFieldPuns`
     * :extension:`NamedWildCards`
     * :extension:`NumericUnderscores`
     * :extension:`PatternGuards`
     * :extension:`PolyKinds`
     * :extension:`PostfixOperators`
     * :extension:`RankNTypes`
     * :extension:`RelaxedPolyRec`
     * :extension:`ScopedTypeVariables`
     * :extension:`StandaloneDeriving`
     * :extension:`StandaloneKindSignatures`
     * :extension:`StarIsType`
     * :extension:`TraditionalRecordSyntax`
     * :extension:`TupleSections`
     * :extension:`TypeApplications`
     * :extension:`TypeOperators`
     * :extension:`TypeSynonymInstances`


.. extension:: Haskell2010
    :shortdesc: Use the Haskell 2010 language variant.

    Compile Haskell 2010 language variant. Enables the
    following language extensions:

    .. hlist::

     * :extension:`CUSKs`
     * :extension:`DatatypeContexts`
     * :extension:`DoAndIfThenElse`
     * :extension:`EmptyDataDecls`
     * :extension:`FieldSelectors`
     * :extension:`ForeignFunctionInterface`
     * :extension:`ImplicitPrelude`
     * :extension:`MonomorphismRestriction`
     * :extension:`PatternGuards`
     * :extension:`RelaxedPolyRec`
     * :extension:`StarIsType`
     * :extension:`TraditionalRecordSyntax`


.. extension:: Haskell98
    :shortdesc: Use the Haskell 98 language variant.

    Compile using Haskell 98 language variant. Enables the
    following language extensions:

    .. hlist::

     * :extension:`CUSKs`
     * :extension:`DatatypeContexts`
     * :extension:`FieldSelectors`
     * :extension:`ImplicitPrelude`
     * :extension:`MonomorphismRestriction`
     * :extension:`NPlusKPatterns`
     * :extension:`NondecreasingIndentation`
     * :extension:`StarIsType`
     * :extension:`TraditionalRecordSyntax`



Although not recommended, the deprecated :ghc-flag:`-fglasgow-exts` flag enables
a large swath of the extensions supported by GHC at once.

.. ghc-flag:: -fglasgow-exts
    :shortdesc: Deprecated. Enable most language extensions;
        see :ref:`options-language` for exactly which ones.
    :type: dynamic
    :reverse: -fno-glasgow-exts
    :category: misc

    The flag ``-fglasgow-exts`` is equivalent to enabling the following extensions:

    .. include:: ../what_glasgow_exts_does.rst

    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.