I'm just starting to learn Haskell. The Prelude is described as a default module:
The Prelude: a standard module. The Prelude is imported by default into all Haskell modules
But this doesn't explain why various documentation has "Prelude" as a prefix in REPL:
Prelude>
I've installed the mingw version via Chocolatey and my REPL shows "ghci" as a prefix, not "Prelude":
GHCi, version 9.2.1: https://www.haskell.org/ghc/ :? for help
ghci>
The Prelude module is loaded though:
GHCi, version 9.2.1: https://www.haskell.org/ghc/ :? for help
ghci> :browse! Prelude
-- imported via Prelude
(!!) :: [a] -> Int -> a
($) :: (a -> b) -> a -> b
...
Why do prefixes differ and what does "Prelude" mean in the interactive compiler?
Prelude is a module that contains a small set of standard definitions and is included automatically into all Haskell modules.
GHCi [1] is GHC's interactive environment that includes an interactive debugger (see The GHCi Debugger). GHCi can. interactively evaluate Haskell expressions. interpret Haskell programs. load GHC-compiled modules.
GHCi will discover which modules are required, directly or indirectly, by the topmost module, and load them all in dependency order. If you started up GHCi from the command line then GHCi's current directory is the same as the current directory of the shell from which it was started.
GHCi is the interactive interface to GHC. From the command line, enter "ghci" (or "ghci -W") followed by an optional filename to load. Note: We recommend using "ghci -W", which tells GHC to output useful warning messages in more situations. These warnings help to avoid common programming errors.
But this doesn't explain why various documentation has "Prelude" as a prefix in REPL.
Since ghci-9.0 it has changed and shows the ghci>
prompt.
Prior to ghci-9.0, the prompt showed the modules that were loaded. For example if you import an module Data.List
, it changes the prompt to:
$ ghci-8.6.5
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
Prelude> import Data.List
Prelude Data.List>
and if we do not load the Prelude
by specifying a -XNoImplicitPrelude
flag, we get:
$ ghci-8.6.5 -XNoImplicitPrelude
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
>
As of ghci-9.0, it shows ghci>
as prompt. Often if you had to work with a lot of modules the prompt was very long, and thus made it inconvenient to work with GHCi.
You can set the prompt to something else with :set prompt "someprompt> "
for example:
$ ghci
GHCi, version 9.0.1: https://www.haskell.org/ghc/ :? for help
ghci> :set prompt "someprompt> "
someprompt>
The prompt has some speciale sequences to show some information as @pedrofurla says. If you want the old behavior back in newer versions of GHCi, then set the prompt to %s>
(and also do :set prompt-cont "%s| "
for multiline prompts):
$ ghci
GHCi, version 9.0.1: https://www.haskell.org/ghc/ :? for help
ghci> :set prompt "%s> "
Prelude> import Data.List
Prelude Data.List>
If you want your change to the prompt to persist into new GHCi sessions, then put the command in ~/.ghci
(creating it if it doesn't exist).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With