# Homework #3

**Due: Mon, Oct 12**

## How to Submit

Submit a single file named

`HW3.hs`

through Canvas.**Read the Homework Policy!**This describes what to do if you cannot solve a problem.

## Description

Template: **HW3.template.hs**

As in the previous assignments, you’ll be defining the functions in the above template. You should download the template above, rename it to `HW3.hs`

, and add your definitions directly to the file.

For each `undefined`

function in the template, you should:

- Write the appropriate type of the function, if it is not provided for you.
- Implement the function.

As before, the file contains `doctest`

comments that illustrate the intended behavior of each function on a few examples. You can use these examples as unit tests using `doctest`

. Feel free to add more examples to improve your test coverage.

### Part 1: Run-length lists

This part consists of two functions for converting between regular lists of elements and a run-length encoding of lists. The types of the functions are already given, so you only need to implement them.

You may find some of the existing list functions in the Prelude helpful. You are also free to write as many helper functions as you would like.

### Part 2: Unary encoding of natural numbers

In this part, you will define several functions for manipulating a simple unary representation of natural numbers. We will return to this encoding of numbers later in the course when we talk about Church encodings in lambda calculus.

**NOTE:** For this part the assignment, you should implement the required mathematical operations by *pattern matching* on and manipulating the unary representation directly. That is, you should *not* implement them by first converting the arguments to integers, doing the mathematical operation on integers, and then converting back to the unary representation.