Questions tagged [ghci]

GHCi is the interactive environment (REPL) for the Glasgow Haskell Compiler.

GHCi is the interactive environment (REPL) for the Glasgow Haskell Compiler and GHCi is one of the main tools used to develope, test and debug Haskell.

Typically, ghci-tag is associated with questions

  • different use cases of ghci, how it works
  • ghci environment settings, tuning
  • customization of ghci environment, scripting
  • how ghci can be used with other tools
  • development of the ghci

There is Haskell-wiki that describes the basic use and customization of GHCi.

1069 questions
21
votes
2 answers

A ghci session without Prelude

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…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
21
votes
3 answers

Defining function signature in GHCi

Defining a function signature in Haskell's interpreter GHCi doesn't work. Copying an example from this page: Prelude> square :: Int -> Int :60:1: error: • No instance for (Show (Int -> Int)) arising from a use of ‘print’ …
jll
  • 805
  • 2
  • 8
  • 16
21
votes
3 answers

Why :sprint always prints a "_"?

Prelude> let a = 3 Prelude> :sprint a a = _ Prelude> let c = "ab" Prelude> :sprint c c = _ Why does it always print a _? I don't quite get the semantics of the :sprint command.
vik santata
  • 2,989
  • 8
  • 30
  • 52
21
votes
3 answers

How to abort execution in GHCI?

When I launch ghci> last [0..] I can interrupt it with Ctrl+C. However ghci> last (repeat 0) cannot be aborted with Ctrl+C. GHCI silently ignores the keystrokes. How to abort this command in GHCI? Is it a bug?
ominug
  • 1,422
  • 2
  • 12
  • 28
21
votes
1 answer

Debugging IO in a package module inside GHCi

I'm doing low-level IO (for library bindings) in Haskell and am experiencing a segfault. I would like to use GHCi's :break to figure out what's going on, but here's what happens: > import SDL > :break SDL.setPaletteColors cannot set breakpoint on…
21
votes
1 answer

What is going on with the types in this ghci session?

I'm learning Haskell, and I was playing around in ghci when I came across something very puzzling. First, create a simple add function: Prelude> let add x y = x + y Note that it works with ints and floats: Prelude> add 3 4 7 Prelude> add 2.5…
Laurence Gonsalves
  • 137,896
  • 35
  • 246
  • 299
20
votes
2 answers

How do I use multiple where clauses in GHCi?

I'm playing around with GHCi for the first time, and I'm having some trouble writing multi-line functions. My code is as follows: Prelude> :{ Prelude| let diffSquares lst = abs $ squareOfSums lst - sumOfSquares lst Prelude| where Prelude| …
T.R.
  • 7,442
  • 6
  • 30
  • 34
20
votes
2 answers

GHCi ignores type signature

Prelude> let myprint = putStrLn . show Prelude> :t myprint myprint :: () -> IO () OK, nothing too unusual here. Just GHCi type defaulting rules, I guess... Prelude> let myprint = (putStrLn . show) :: Show x => x -> IO () Prelude> :t myprint myprint…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
20
votes
3 answers

How can I set my GHCi prompt to a lambda character on Windows?

I want to have a lambda (λ) symbol as my prompt in GHCi (7.8) on Windows 7, so I set up my .ghci file as :set +m :set prompt "λ: " :set prompt2 " | " And I set my console font to Lucida Console since it's supposed to support Unicode, but when I…
bheklilr
  • 53,530
  • 6
  • 107
  • 163
20
votes
1 answer

Strange GHCi lazy evaluation

I define two mutually recursive lists for even and odd numbers in ghci as follows: > let evens = 0:map (+1) odds; odds = map (+1) evens And then I consult the thunks using :sp > :sp evens evens = _ > :sp odds odds = _ > take 5 evens [0,2,4,6,8] >…
is7s
  • 3,500
  • 1
  • 20
  • 41
20
votes
1 answer

Break and continue in GHCi debugger without use of breakpoints

In a traditional imperative debugger such as gdb it is possible to break into program executing with SIGINT, inspect the program state, and eventually resume execution. While GHCi allows one to break into program execution at an arbitrary point with…
bgamari
  • 5,913
  • 1
  • 18
  • 21
19
votes
6 answers

How do you check the type of a local variable?

Simple question. Is it possible to check the type of a variable that is only alive within a function? For example: main = do x <- something How can I check the type of x? I can't do :type x in ghci because x is not global.
Nick Brunt
  • 9,533
  • 10
  • 54
  • 83
19
votes
1 answer

Warnings on load from GHCi prompt

When using GHCi I'd like to know how can I use the -Wall option when (re)loading from the prompt. For example in section 3.3 of Haskell Programming Tips The example shown with guards is as follows: -- Bad implementation: fac :: Integer ->…
Sarah Tattersall
  • 1,275
  • 2
  • 21
  • 32
18
votes
1 answer

In GHCi, why does the kind of the function arrow `:kind (->)` include question marks `(->) :: ?? -> ? -> *`?

Possible Duplicate: Haskell Weird Kinds: Kind of (->) is ?? -> ? -> * In GHCi (version 7.0.2), if I ask for the kind of the function type, the result has question marks: Prelude> :kind (->) (->) :: ?? -> ? -> * Why does the kind include question…
wl.
  • 2,270
  • 3
  • 18
  • 13
18
votes
1 answer

Disable printing of IO results in GHCi?

When running IO actions in GHCi prompt it automatically runs the action and shows result, this is nice, but not for students trying to understand difference between IO and non-IO. Is there a way to change configuration of GHCi so that it runs the…
Vladimir Still
  • 634
  • 3
  • 17