summaryrefslogtreecommitdiff
path: root/docs/users_guide/exts/nullary_type_classes.rst
blob: 516854f5cf4f08f95b6f2048033e4179505dc063 (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
.. _nullary-type-classes:

Nullary type classes
~~~~~~~~~~~~~~~~~~~~

.. extension:: NullaryTypeClasses
    :shortdesc: Deprecated, does nothing. nullary (no parameter) type
        classes are now enabled using :extension:`MultiParamTypeClasses`.

    :since: 7.8.1

    :status: Deprecated

    Allow use and definition of type classes with no parameters. This extension
    has been replaced by :extension:`MultiParamTypeClasses`.


Nullary (no parameter) type classes are enabled with
:extension:`MultiParamTypeClasses`; historically, they were enabled with the
(now deprecated) :extension:`NullaryTypeClasses`. Since there are no available
parameters, there can be at most one instance of a nullary class. A nullary type
class might be used to document some assumption in a type signature (such as
reliance on the Riemann hypothesis) or add some globally configurable settings
in a program. For example, ::

      class RiemannHypothesis where
        assumeRH :: a -> a

      -- Deterministic version of the Miller test
      -- correctness depends on the generalised Riemann hypothesis
      isPrime :: RiemannHypothesis => Integer -> Bool
      isPrime n = assumeRH (...)

The type signature of ``isPrime`` informs users that its correctness depends on
an unproven conjecture. If the function is used, the user has to acknowledge the
dependence with: ::

      instance RiemannHypothesis where
        assumeRH = id