Installing Haskell

The Haskell Platform

The fastest and easiest way to install Haskell is through the Haskell Platform. It includes the compiler (GHC), the build system (Cabal), the base libraries, and a few other helpful tools. It should only take a few seconds to install everything. When it finishes installing, open your console and type the commands shown below to check if it installed correctly.

Throughout this book, examples of input to your console will be shown as lines starting with a $ character. Type whatever follows on the same line into your console. The lines that come afterward are the ouput of the command.

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.2

$ cabal --version
cabal-install version
compiled using version of the Cabal library

If your output looks like this, then you are ready to go!

Running the Interpreter

GHCi (which is an acronym for Glasgow Haskell Compiler Interactive) is an interactive compiler. If you give it an expression, it will evaluate it and then print the result to the screen. This kind of software is sometimes called a REPL (Read Evaluate Print Loop), because it reads your input, evaluates it, prints the result to the screen, and then waits for more input so it can start the process all over again in an infinite loop. From now on, we will just call it ghci. To start it up, type ghci in your console.

$ ghci
GHCi, version 8.4.2:  :? for help

Throughout this book, examples of input to ghci will be shown as lines starting with a > character. All text that follows on the same line after this character is an input to ghci. The lines below it are the ouput (the result of ghci evaluating your expression). With ghci running, type 1 + 2 just like below, then hit the Enter or Return key.

> 1 + 2

Type :quit to exit ghci.

> :quit
Leaving GHCi.