summaryrefslogtreecommitdiff
path: root/docs/users_guide/exts/traditional_record_syntax.rst
blob: 842af80652557ac8d33b53ca8ea2b18b9a003b39 (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
.. _traditional-record-syntax:

Traditional record syntax
-------------------------

.. extension:: NoTraditionalRecordSyntax
    :shortdesc: Disable support for traditional record syntax
        (as supported by Haskell 98) ``C {f = x}``

    :since: 7.4.1

    Disallow use of record syntax.

Traditional record syntax, such as ``C {f = x}``, is enabled by default.
To disable it, you can use the :extension:`NoTraditionalRecordSyntax` extension.

Under :extension:`NoTraditionalRecordSyntax`, it is not permitted to define a
record datatype or use record syntax in an expression.  For example, the
following all require :extension:`TraditionalRecordSyntax`:

.. code-block:: haskell

     data T = MkT { foo :: Int }  -- record datatype definition

     x = MkT { foo = 3 }          -- construction

     y = x { foo = 3 }            -- update

     f (MkT { foo = i }) = i      -- pattern matching

However, if a field selector function is in scope, it may be used normally.
(This arises if a module using :extension:`NoTraditionalRecordSyntax` imports a
module that defined a record with :extension:`TraditionalRecordSyntax` enabled).
If you wish to suppress field selector functions, use the
:extension:`NoFieldSelectors` extension.