You have two options:

- Use haskell on ieng6. Just log in with your class account,
*prep cs105f*if necessary, and you are ready to go. Class accounts should be set up by the first day of classes for students in all sections. For issues with your ucsd computer account, contact ACMS. - Install the Haskell Platform on your own computer, and then issue the commands
*cabal update*and*cabal install xml*to get the xml parsing library used for interoperability with JFLAP.

**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!

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
2
```

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.

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*(*x*^{2}) to illustrate its meaning.

- Haskell is a functional programming language. Programs are written as functions
*f*:*X*→*Y*that on input a value*x*∈*X*produce some other value*f*(*x*)∈*Y*. - Function invocation is written without parentheses, i.e., as "
`f x`

" rather than "*f*(*x*)" - Functions of several arguments (
*f*:*X*×*Y*→*Z*) are usually*curried*, which means that*f*is written as a function that on input*x*∈*X*outputs, as a result, a function from*Y*to*Z*. So, formally*f*:*X*→ (*Y*→*Z*). If you want to apply*f*to*x*and*y*, you first apply it to*x*, and then you apply the result*f*(*x*) to*y*. Since parentheses are not required, this is written simply as`f x y`

- Haskell is a typed language: every value has a corresponding type. To a large extent, you can think of types as
*sets*of possible values that a given variable may take. The assertion that a given`value`

has a certain`type`

is written as`value::type`

. You can think of`v::T`

as the mathematical statement*v*∈*T*, i.e., the value*v*belongs to the set represented by the type*T*. - Before any function definition, we usually give a function declaration that specifies the type of the function. Function declarations are written as
`f::Int->Int`

, which corresponds to the mathematical notation*f*:*Z*→*Z*(i.e.,*f*is a function from the integers to the integers.) - Haskell uses indentation to delimit blocks of code, similarly to python. So, be careful on how you format your functions, and don't use TABs, or make sure to use an editor that expands TABs into spaces.
- Haskell has strict conventions about the use of upper and lower case identifiers. By and large, functions and values start with a lowercase letters, while types start with uppercase.