Using an interactive shell (REPL)

Haskell:
Using an interactive shell (REPL)

How to:

To start the GHCi (Glasgow Haskell Compiler’s interactive environment), simply type ghci in your terminal. Here’s how to use it:

Prelude> let x = 5
Prelude> x * 2
10
Prelude> :t x
x :: Num a => a

Sample output explains that x is a numeric variable and shows that doubling it results in 10.

Deep Dive:

Haskell’s GHCi has come a long way since its inception. It provides a rich set of features like tab completion, multi-line input, and package loading. Alternatives like Hugs are mostly historical now, with GHCi being the standard. GHCi compiles code just-in-time each time you enter an expression, giving you an efficient way to test your Haskell code.

See Also: