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
191
votes
7 answers

How to define a function in ghci across multiple lines?

I'm trying to define any simple function that spans multiple lines in ghci, take the following as an example: let abs n | n >= 0 = n | otherwise = -n So far I've tried pressing Enter after the first line: Prelude> let abs n | n >= 0 =…
Peter McG
  • 18,857
  • 8
  • 45
  • 53
162
votes
5 answers

Multi-line commands in GHCi

I am having problem in entering multi-line commands in ghci. The following 2-line code works from a file: addTwo :: Int -> Int -> Int addTwo x y = x + y But when I enter in ghci, I get an error: :1:1: error: Variable not in scope:…
R71
  • 4,283
  • 7
  • 32
  • 60
128
votes
1 answer

How do I enable language extensions from within GHCi?

I'm trying to enable XRankNTypes in GHCi. How do I do this?
Matt Fenwick
  • 48,199
  • 22
  • 128
  • 192
123
votes
1 answer

Emacs Interactive-Haskell repl non-response if either the cabal or working directory set to project directory

I'm running into odd behavior with the Interactive-Haskell repl in emacs. When I source a file, the emacs mini buffer shows a series of interactive prompts: Start a new project named 'myproject'? Cabal dir (guessed from myproject.cabal): Build…
daj
  • 6,962
  • 9
  • 45
  • 79
103
votes
8 answers

How do I clear the terminal screen in Haskell?

How can I clear a terminal screen after my user has selected an option from my application's menu?
Nubkadiya
  • 3,285
  • 13
  • 40
  • 45
93
votes
3 answers

Why does ghci desugar type lists and type families? Can this be selectively disabled?

I'm trying to make the types ghci displays for my libraries as intuitive as possible, but I'm running into a lot of difficulties when using more advanced type features. Let's say I have this code in a file: {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE…
Mike Izbicki
  • 6,286
  • 1
  • 23
  • 53
87
votes
3 answers

How to provide explicit type declarations for functions when using GHCi?

How to I define the equivalent of this function (taken from learnyouahaskell) inside GHCi? import Data.List numUniques :: (Eq a) => [a] -> Int numUniques = length . nub Without the type declaration, GHCi accepts the function definition, but…
mattbh
  • 5,230
  • 2
  • 27
  • 27
83
votes
4 answers

How to run a Haskell file in interpreted mode

I've been told you can interpret Haskell files (which I assume means they will work like Ruby/Python/Perl). I can't find the command line option on GHC to do this, though. It always wants to compile my file. Took a look at GHCi as well, but it…
Joshua Cheek
  • 30,436
  • 16
  • 74
  • 83
70
votes
1 answer

What is the best way to test and interact with inner functions defined inside a toplevel function?

When I program in Javascript, I find it extremely convenient to be able to use the debugger to halt program execution at any point and to be able to runs commands and inspect variables from there. Now, back in Haskell, is there a way to run…
hugomg
  • 68,213
  • 24
  • 160
  • 246
65
votes
3 answers

How can I view the definition of a function in Haskell/GHCi?

I'm using Haskell 2010.1.0.0.1 with GHC 6. Typing :t at the GHCi prompt followed by the name of a function shows us the type of the function. Is there a way to view the function definition as well?
franco hades
  • 653
  • 1
  • 5
  • 4
58
votes
2 answers

ghci 'Not in scope:' message

I'm going through the 'Learn you a Haskell' tutorial and I am at this part: lucky :: (Integral a) => a -> String When I try to execute this line I get: :1:1: Not in scope: `lucky' What am I doing wrong?
user181351
56
votes
2 answers

How to make a Haskell cabal project with library+executables that still run with runhaskell/ghci?

If you declare a library + executable sections in a cabal file while avoiding double compilation of the library by putting the library into a hs-source-dirs directory, you cannot usually run your project with ghci and runhaskell anymore, especially…
nh2
  • 24,526
  • 11
  • 79
  • 128
53
votes
4 answers

ghci configuration file

I'm using ghci 6.8.2 on Ubuntu. Does ghci use a configuration file where we can do some initial setup?. E.g.: :set prompt "ghci> ".
rturrado
  • 7,699
  • 6
  • 42
  • 62
50
votes
1 answer

GHCI can't load module if both package-conf and source path contains it

I encounter a strange situation in GHCI, don't know if anyone observed similar case. For some module, when I have it in the search path both by -package-conf, and also by -i, GHCI fails when I try to import the module with 'module is not loaded:…
ron
  • 9,262
  • 4
  • 40
  • 73
50
votes
1 answer

GHCi runtime linker issue when using FFI declarations

I have a problem regarding FFI in Haskell and the interactive mode of GHC again. Consider FFISo.hs: {-# LANGUAGE OverloadedStrings #-} module Main where import qualified Data.ByteString.Char8 as B import FFIFun.Foo main :: IO () main = do …
lewurm
  • 1,103
  • 7
  • 19
1
2 3
71 72