GHCi is GHC's interactive environment, in which Haskell expressions can be interactively evaluated and programs can be interpreted. If you're famililar with Hugs, then you'll be right at home with GHCi. However, GHCi also has support for interactively loading compiled code, as well as supporting allthe language extensions that GHC provides.
Let's start with an example GHCi session. You can fire up GHCi with the command ghci:
$ ghci ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 5.00, For Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package std ... linking ... done. Prelude>
There may be a short pause while GHCi loads the prelude and standard libraries, after which the prompt is shown. If we follow the instructions and type :? for help, we get:
Commands available from the prompt: <stmt> evaluate/run <stmt> :cd <dir> change directory to <dir> :def <cmd> <expr> define a macro :<cmd> :help, :? display this list of commands :load <filename> load a module (and it dependents) :module <mod> set the context for expression evaluation to <mod> :reload reload the current module set :set <option> ... set options :type <expr> show the type of <expr> :unset <option> ... unset options :quit exit GHCi :!<command> run the shell command <command> Options for `:set' and `:unset': +r revert top-level expressions after each evaluation +s print timing/memory stats after each evaluation +t print type after evaluation -<flag> most GHC command line flags can also be set here (eg. -v2, -fglasgow-exts, etc.)
We'll explain most of these commands as we go along. For Hugs users: many things work the same as in Hugs, so you should be able to get going straight away.
Haskell expressions can be typed at the prompt:
Prelude> 1+2 3 Prelude> let x = 42 in x / 9 4.666666666666667 Prelude>
GHCi interprets the whole line as an expression to evaluate. The expression may not span several lines - as soon as you press enter, GHCi will attempt to evaluate it.
The ‘i’ stands for “Interactive”
except the FFI, at the moment