Home > front end >  What does the "Prelude" prefix mean in GHCi?
What does the "Prelude" prefix mean in GHCi?

Time:11-28

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?

CodePudding user response:

But this doesn't explain why various documentation has "Prelude" as a prefix in REPL.

Since it has changed and shows the ghci> prompt.

Prior to , 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 , 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> :

$ 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).

  • Related