Difference between revisions of "Prelude"
MichalPalka (talk | contribs) (Add an article on prelude an avoiding its automatic import) |
m |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
The documentation of prelude from [[GHC]] can be found [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html here]. |
The documentation of prelude from [[GHC]] can be found [http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html here]. |
||
− | ==Avoiding |
+ | ==Avoiding Prelude== |
− | If you wish to program without a prelude or to use a custom version of it you can suppress its automatic inclusion in several ways. |
+ | If you wish to program without a prelude or to use a custom version of it you can suppress its automatic inclusion in several ways. The problem is also tackled in a [[No import of Prelude|FAQ entry]]. |
− | ===Explicit import |
+ | ===Explicit import declaration === |
− | By including an explicit import declaration of |
+ | By including an explicit import declaration of Prelude as follows |
<haskell> |
<haskell> |
||
import Prelude () |
import Prelude () |
||
Line 13: | Line 13: | ||
The empty import list in the parenthesis causes nothing to be imported while the automatic import is prevented as well. |
The empty import list in the parenthesis causes nothing to be imported while the automatic import is prevented as well. |
||
===Language option=== |
===Language option=== |
||
− | [[GHC]] supports a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html#options-language language option] -XNoImplicitPrelude (or -fno-implicit-prelude in older [[GHC]]) that makes it not import |
+ | [[GHC]] supports a [http://www.haskell.org/ghc/docs/latest/html/users_guide/ghc-language-features.html#options-language language option] -XNoImplicitPrelude (or -fno-implicit-prelude in older [[GHC]]) that makes it not import Prelude implicitly. The option can be also specified by adding: |
<haskell> |
<haskell> |
||
{-# LANGUAGE NoImplicitPrelude #-} |
{-# LANGUAGE NoImplicitPrelude #-} |
||
Line 20: | Line 20: | ||
This option makes it possible to rebind the monadic <hask>do</hask> syntax. |
This option makes it possible to rebind the monadic <hask>do</hask> syntax. |
||
+ | |||
+ | [[Category:Glossary]] |
Latest revision as of 22:09, 28 June 2021
Prelude is a module that contains a small set of standard definitions and is included automatically into all Haskell modules.
Documentation
The documentation of prelude from GHC can be found here.
Avoiding Prelude
If you wish to program without a prelude or to use a custom version of it you can suppress its automatic inclusion in several ways. The problem is also tackled in a FAQ entry.
Explicit import declaration
By including an explicit import declaration of Prelude as follows
import Prelude ()
The empty import list in the parenthesis causes nothing to be imported while the automatic import is prevented as well.
Language option
GHC supports a language option -XNoImplicitPrelude (or -fno-implicit-prelude in older GHC) that makes it not import Prelude implicitly. The option can be also specified by adding:
{-# LANGUAGE NoImplicitPrelude #-}
on top of the module.
This option makes it possible to rebind the monadic do
syntax.