Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A ghci session without Prelude

Tags:

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?

like image 279
Dan Burton Avatar asked Oct 11 '11 21:10

Dan Burton


People also ask

What is Prelude in GHCi?

Prelude is a module that contains a small set of standard definitions and is included automatically into all Haskell modules.

How do I run a GHCi file?

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.

How do I get out of Haskell Prelude?

Quits GHCi. You can also quit by typing control-D at the prompt. Attempts to reload the current target set (see :load ) if any of the modules in the set, or any dependent module, has changed.

How do you define a function in GHCi?

Simply type a let followed by a newline: let ⏎. Then fac 0 = 1 ⏎. Then fac n = n * fac (n-1) ⏎ ⏎ and you're done!


2 Answers

% 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?

like image 168
Roman Cheplyaka Avatar answered Oct 07 '22 00:10

Roman Cheplyaka


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

Prelude> :set -XNoImplicitPrelude
Prelude> :m -Prelude
> 
like image 22
Qwertie Avatar answered Oct 06 '22 23:10

Qwertie