LinuxCommandLibrary

ghci

Run Haskell code interactively

TLDR

Start a REPL (interactive shell)

$ ghci
copy

Start a REPL and load the specified Haskell source file
$ ghci [source_file.hs]
copy

Start a REPL and enable a language option
$ ghci -X[language_option]
copy

Start a REPL and enable some level of compiler warnings (e.g. all or compact)
$ ghci -W[warning_level]
copy

Start a REPL with a colon-separated list of directories for finding source files
$ ghci -i[path/to/directory1:path/to/directory2:...]
copy

SYNOPSIS

ghci [GHCi flags] [GHC flags] [input-files]

PARAMETERS

-h, --help
    Display help and exit

-V, --version
    Show version information

--interactive
    Force interactive mode even with input files

--no-global
    Skip loading startup files (.ghci, etc.)

-i
    Add directories to module import search path

-l
    Load specified files as modules

--ghci-script=FILE
    Load commands from script file

-e EXPR
    Evaluate expression and exit (non-interactive)

DESCRIPTION

GHCI (Glasgow Haskell Compiler Interactive) is a read-eval-print loop (REPL) for the Haskell programming language. It provides an interactive environment to evaluate expressions, load and reload modules, inspect types, and debug code.

Invoke ghci to enter the prompt (Prelude>), where you can type Haskell code directly. Use colon-commands like :load file.hs to compile modules, :type expr for type signatures, :info ident for details, and :quit to exit. Supports tab-completion, multi-line input with :{ and :}, and history.

Ideal for prototyping, learning Haskell, testing functions, and exploratory programming. Integrates with GHC flags for customization. Requires GHC installation via package managers like apt install ghc on Debian-based systems.

CAVEATS

GHCI requires GHC; not available on minimal systems. Performance may vary with large modules. Startup files can affect reproducibility.

KEY IN-REPL COMMANDS

:l or :load file: Load module
:r or :reload: Reload current module
:t or :type expr: Show type
:?: List all commands

STARTUP FILES

Executed on start: ~/.ghci, ./.ghci, $GHCi_PATH. Use for custom prelude or settings.

HISTORY

Introduced in GHC 6.4 (2005) as full-featured REPL; evolved from earlier GHCi modes since GHC 4.x (late 1990s). Maintained by GHC team, with ongoing enhancements for Haskell features.

SEE ALSO

ghc(1), runghc(1), stack(1)

Copied to clipboard