diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2013-03-13 21:10:20 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-03-13 21:10:20 +0000 |
commit | 5319ea79fa1572b7d411548532031f9d19b928c6 (patch) | |
tree | 6094260c301c82513428c77c9e762ef3a431572d /docs | |
parent | f574b69cd81ba5a730cb1c64b08c3892e42308a3 (diff) | |
download | haskell-5319ea79fa1572b7d411548532031f9d19b928c6.tar.gz |
Implement nullary type classes (#7642)
This is a slightly refined version of a patch by shachaf,
done by Krzysztof Gogolewski <krz.gogolewski@gmail.com>.
Diffstat (limited to 'docs')
-rw-r--r-- | docs/users_guide/flags.xml | 6 | ||||
-rw-r--r-- | docs/users_guide/glasgow_exts.xml | 29 |
2 files changed, 35 insertions, 0 deletions
diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index f5f51b0d4e..4766e5a520 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -1124,6 +1124,12 @@ <entry><option>-XNoMultiParamTypeClasses</option></entry> </row> <row> + <entry><option>-XNullaryTypeClasses</option></entry> + <entry>Enable <link linkend="nullary-type-classes">nullary (no parameter) type classes</link>.</entry> + <entry>dynamic</entry> + <entry><option>-XNoNullaryTypeClasses</option></entry> + </row> + <row> <entry><option>-XFunctionalDependencies</option></entry> <entry>Enable <link linkend="functional-dependencies">functional dependencies</link>.</entry> <entry>dynamic</entry> diff --git a/docs/users_guide/glasgow_exts.xml b/docs/users_guide/glasgow_exts.xml index 16d180aaba..c396237f27 100644 --- a/docs/users_guide/glasgow_exts.xml +++ b/docs/users_guide/glasgow_exts.xml @@ -3795,6 +3795,35 @@ We use default signatures to simplify generic programming in GHC </sect3> + +<sect3 id="nullary-type-classes"> +<title>Nullary type classes</title> +Nullary (no parameter) type classes are enabled with <option>-XNullaryTypeClasses</option>. +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, + +<programlisting> + class RiemannHypothesis where + assumeRH :: a -> a + + -- Deterministic version of the Miller test + -- correctness depends on the generalized Riemann hypothesis + isPrime :: RiemannHypothesis => Integer -> Bool + isPrime n = assumeRH (...) +</programlisting> + +The type signature of <literal>isPrime</literal> informs users that its correctness +depends on an unproven conjecture. If the function is used, the user has +to acknowledge the dependence with: + +<programlisting> + instance RiemannHypothesis where + assumeRH = id +</programlisting> + +</sect3> </sect2> <sect2 id="functional-dependencies"> |