# Haskell/Basic Haskell
## The Haskell Compiler

While there are various implementations of Haskell, for the purposes of this course we will only be using GHC, the Glasgow Haskell Compiler, and any references to compiling or running Haskell will assume a modern version of GHC (version 7.10 or 8).

### Installing GHC

TODO: update this section and talk about Cabal and Stack.

#### Linux

If you're on Linux, you might have a package manager, where you can install GHC. If you're not that lucky you should try and build it from source. Get the source from the website: http://www.haskell.org/ghc/download.html

### Using GHC

Now that GHC is installed, let's write a simple "Hello world"-program (We'll explain this in detail later):
Put the above in a file called HelloWorld.hs

#### GHC

To run it with ghc type:
Now you should have a file called HelloWorld which you can run, and it should print:
great.

#### runghc

runghc is very much like ghc, but instead of making an executable file, it simply runs the program, without making any new files.

#### GHCi

With your installation of GHC you should also have a program called ghci, an interactive version of the Haskell compiler. Interactive interfaces to compilers are often called REPLs or read, eval, print, loops. When run, you should see output similar to:
Note: the Prelude is a collection of commonly used functions, like a standard library, that allow us to more easily write Haskell without having to remember to import the same libraries in every program. It is imported by default.
The line
in GHCI tells us which modules are currently in scope. However we can change it to whatever we like with the set command. For example:
Note: all commands to GHCI are prefixed with a colon. As GHCI says when you start it, you can view these commands with :? or :help.
Users of the Vim text editor may find various commands in GHCI are equivalent, such as :! for running shell commands from inside of GHCI. For example:
Finally it is worth noting that GHCI has a scrollable history (with the arrow keys) and tab completion.

## Setting up and becoming familiar with GHCI

For the purposes of learning Haskell, we'll want to change some of GHCI's default settings. Start by turning on type signatures:
Now when we give GHCI input it will print out the type of the expression as well as what it evaluates to!
The last value given to GHCI is bound to the name it, thus we can re-evaluate it by typing:
Finally, it's worth noting that type signatures can be checked without evaluating an expression (which is useful if GHCI doesn't know how to print that type of value (such as functions)). This can be done with :type or :t

### Type signatures

Okay, so now that we've got GHCI to tell us about the types of things, we need to learn what it's actually saying.
Note: GHC and GHCI can have intimidating error messages when you first start. Try to break down the error message into small pieces and follow the types.
The notation :: indicates a type signature and can be pronounced as is of type or is a. Thus the English equivalent to "Hello, World" :: String is "Hello, World" is a String. But wait, wasn't the type of "Hello, World" [Char]? Yes! Haskell uses type synonyms to try and keep things simple whenever possible. You can find out information about various Haskell terms with the :info or :i command. So when we investigate String we find out that it's the same as [Char]: