---
# System prepended metadata

title: Lab Exercise 2

---

# Lab Exercise 2

Add this snippet to the bottom of your function definitions

```haskell
main :: IO ()
main = return ()
```

##### If-then-else syntax in Haskell
```haskell=
if cond then this else that
```

#### Easy functions

- `cube :: Int -> Int` - Consumes an integer and produces the cube of that integer
- `double :: Int -> Int` - Consumes an integer and produces the 2 times that integer

#### Recursive Functions

- `modulus :: Int -> Int -> Int` - Consumes two integers $x$ and $m$ and produces $x \mod m$ 
- `factorial :: Int -> Int` - Consumes an integer and produces the factorial of the integer

#### Higher order function

- `compose :: (Int -> Int) -> (Int -> Int) -> (Int -> Int)` - Consumes two functions $f : \mathbb{Z} \to \mathbb{Z}$, and $g:  \mathbb{Z} \to \mathbb{Z}$ and produces the function $f \circ g$.
- `subtractMaker :: Int -> (Int -> Int)` - Consumes an integer $x$ and produces a function that consumes an integer $y$ and produces $x-y$
- `applyNTimes :: (Int -> Int) -> Int -> Int -> Int` - Consumes a function $f: \mathbb{Z} \to \mathbb{Z}$ and and two integers $n$ and $x$. `applyNTimes` produces an integer which is the result of the function applied to $x$, $n$-times. Similar to `applyTwice` but instead of two times, you're applyung the function $n$-times.