summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLawton Nichols <lawtonnichols@gmail.com>2022-10-26 13:15:33 -0700
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-11-23 12:45:55 -0500
commite153851650bbba631f3a6926ba42422f9f1fa0cd (patch)
tree8af2056def37405a8f9de806e25d6084ee44d6d3
parent04d0618c16157f61cc03981f8875c96a9adeb879 (diff)
downloadhaskell-e153851650bbba631f3a6926ba42422f9f1fa0cd.tar.gz
Add documentation on custom Prelude modules (#22228)
Specifically, custom Prelude modules that are named `Prelude`.
-rw-r--r--docs/users_guide/exts/rebindable_syntax.rst45
1 files changed, 42 insertions, 3 deletions
diff --git a/docs/users_guide/exts/rebindable_syntax.rst b/docs/users_guide/exts/rebindable_syntax.rst
index 3b41d5097b..4955e17c11 100644
--- a/docs/users_guide/exts/rebindable_syntax.rst
+++ b/docs/users_guide/exts/rebindable_syntax.rst
@@ -14,9 +14,7 @@ Rebindable syntax and the implicit Prelude import
GHC normally imports ``Prelude.hi`` files for
you. If you'd rather it didn't, then give it a ``-XNoImplicitPrelude``
-option. The idea is that you can then import a Prelude of your own. (But
-don't call it ``Prelude``; the Haskell module namespace is flat, and you
-must not conflict with any Prelude module.)
+option. The idea is that you can then import a Prelude of your own.
.. extension:: RebindableSyntax
:shortdesc: Employ rebindable syntax.
@@ -91,6 +89,47 @@ Be warned: this is an experimental facility, with fewer checks than
usual. Use ``-dcore-lint`` to typecheck the desugared program. If Core
Lint is happy you should be all right.
+Custom Prelude modules named ``Prelude``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you call your custom Prelude module ``Prelude`` and place it in a file called
+``Prelude.hs``, then your custom Prelude will be implicitly imported instead of
+the default Prelude.
+
+Here is an example that compiles: ::
+
+ $ cat Prelude.hs
+ module Prelude where
+
+ a = ()
+
+ $ cat B.hs
+ module B where
+
+ foo = a
+
+ $ ghc Prelude.hs B.hs
+ [1 of 2] Compiling Prelude ( Prelude.hs, Prelude.o )
+ [2 of 2] Compiling B ( B.hs, B.o )
+
+The new ``Prelude`` is implicitly imported in ``B.hs``.
+
+Here is an example that does not compile: ::
+
+ $ cat Prelude.hs
+ module Prelude where
+
+ foo = True
+
+ $ ghc Prelude.hs
+ [1 of 1] Compiling Prelude ( Prelude.hs, Prelude.o )
+
+ Prelude.hs:3:7: error: Data constructor not in scope: True
+
+The original ``Prelude`` module is shadowed by the custom Prelude in this case.
+To include the original Prelude in your custom Prelude, you can explicitly
+import it with the ``-XPackageImports`` option and ``import "base" Prelude``.
+
Things unaffected by :extension:`RebindableSyntax`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~