21

This question arose on #haskell irc chat:

How can I start ghci without importing prelude?

The possible answer seemed obvious:

ghci -XNoImplicitPrelude, or load a file with import Prelude ()

The latter seems to work, while the former strangely does not. However, import Prelude () imports the declared instances from Prelude, right? Is there a better way of creating a ghci session without loading Prelude at all?

Dan Burton
  • 53,238
  • 27
  • 117
  • 198

2 Answers2

17
% ghci                    
GHCi, version 7.0.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :m -Prelude 
> :i map

Top level: Not in scope: `map'
> :i Eq

Top level: Not in scope: data constructor `Eq'

However, I'm not sure about the instances and how ghci deals with them.

Is there a particular instance that you're concerned about?

Roman Cheplyaka
  • 37,738
  • 7
  • 72
  • 121
  • "Is there a particular instance that you're concerned about?" Not really. Just concerned in general. I would imagine that `:m -Prelude` kills the instances, though. – Dan Burton Oct 12 '11 at 19:59
  • 1
    I'm not sure the instances particularly matter, though, as the relevant classes would also be killed, so there'd be no way to get at them. – javawizard Nov 08 '12 at 05:35
  • 3
    @NikitaVolkov: yes (and I find it strange), but now `-XNoImplicitPrelude` seems to work as Dan expected (at least in GHC 7.6) – Roman Cheplyaka Jan 12 '13 at 22:39
4

The accepted answer doesn't seem to work anymore. This does work in ghci 8.0.2.

Prelude> :set -XNoImplicitPrelude
Prelude> :m -Prelude
> 
Qwertie
  • 5,784
  • 12
  • 45
  • 89