Quick Start Guide for the impatient

You have two options:

Important: Haskell programs are much easier to read and write using an editor with Haskell syntax highlighting and formatting support. See editor support for a number of supported editors. You are probably better off sticking to what you normally use, just make sure it is a programming editor that replaces TABs with sequences of spaces. Haskell, similarly to Python and dg, uses an indentation aware syntax, and is easily confused by TABs!

Getting started with Haskell

Translating mathematical definitions and theorems into computer programs is especially easy when using a high level programming language, like Haskell. If you have never used Haskell before, don't worry. While some prior knowledge of haskell (or other functional programming languages) may be helpful, it is not strictly required. We will only use a very small subset of the features of the Haskell programming language, and you can pick up the language as we use it in class.

For your convenience, we have already installed the ghc Haskell compiler in the class directory (cs105f) on ieng6. So, all you need to do in order to start using Haskell is to log in into your class/school account on ieng6, and prep cs105f if necessary.

Alternatively, you can download and install the Haskell Platform on your own computer. Haskell is freely available and well supported on a variety of operating systems, so it should be an easy install. For alternative installation methods see the downloads page. The version of ghc installed on ieng6, is 7.10.2, but any recent version is fine, including the ghc 8 shipped with the most recent version of the Haskell Platform.

In the following, it is assumed you are logged in, and ready to enter commands at the ieng6 shell prompt ieng6$. Check that everything is working properly by issuing the following commands at the prompt:

ieng6$ prep cs105f
  ieng6$ ghci
  GHCi version 7.10.2 ...   
  Prelude> 1+1

Congratulations, you just used Haskell to compute 1+1! Next, follow the examples at Starting Out to evaluate some more complex Haskell expressions. You can leave GHCi issuing the command :q or simply typing control-D.

For more complex examples, you will want to use a text editor to type your programs. Let's try that out. Use your favorite text editor to type the following (one line) program into a file hello.hs:

main = putStrLn "Hello, World!"  

You can run the program (from the command line shell) using the command

ieng6$ runhaskell hello.hs
  Hello, World!

You can also compile your program into an executable and run it with the commands

ieng6$ ghc hello.hs
  [1 of 1] Compiling Main ...   
  ieng6$ hello  
  Hello, World!  

or load it from within ghci with :l hello.hs, and then execute it by evaluating main at the ghci prompt.

In order to compile some programs, you may also need some additional packages, like the xml package which you can install on your computer with the commands cabal update, cabal install xml. All required packages are already (or will be) installed on ieng6. Installing packages is only needed if you use your own computer.

Programming in Haskell

For a good tutorial introduction to the language we recommend "Learn you a Haskell for Great Good!". Going through the first few chapters should be more than enough: we will only use the most basic features of the language. If you want to dig deeper into haskell, you can find plenty of documentation and other resources at www.haskell.org.

If you are not familiar with any language in the haskell family, here are a few notes that may save you a few headaches. As a notational convention, we use this font when referring to haskell syntax, and use mathematical notation f(x2) to illustrate its meaning.