Install the Haskell Platform or cabal + ghc.

Hello World


main = putStrLn "Hello, world"

Put this in a file (hello_world.hs). Compile it with ghc hello_world.hs, and run the executable.


Interpreter for Haskell. Not quite a read-execute loop like other languages, but it's useful.


add arg1 arg2 = arg1 + arg2
five = add 2 3

Haskell is a pure functional language.

This program will cause an infinite loop (the program "diverges"), because the variable x in main is defined in terms of itself, not in terms of the declaration x = 5:

x = 5

main = let x = x + 1
        in print x

How can you program without mutable variables?


Guards and where clauses

Variable names


Every expression and binding has a type (it is strongly typed)

Haskell uses function currying.

Defining data types

Types start with capital letters.

data PointT = PointC Double Double deriving show


So common that Haskell has Lists as a predefined type with syntactic sugar. Strings are just lists of Chars.


Two constructors: x:rest and [].

Note on error code:

Other methods

Parsing with deriving Read and reads

Useful tool: Hoogle

A search engine for Haskell and the Haskell libraries. David Mazieres recommends that you make this a keyword in your search bar! Haskell may have a steep learning curve, but it is relatively easy to understand what code is doing (with tools like this).

Example: counting letters

Due to thunks you don't actually have to keep an intermediate list in memory at any point in time (see example in slides)

Function composition

Lambda Extraction

Infix vs Prefix notation