# Homework #2

Due: Wed, Oct 4, 10:59pm

## How to Submit

• Submit a single file named HW2.<your-username>.hs through TEACH.

• Your submission must compile without errors in GHCi. Put all non-working parts of your solution in comments.

• Please preserve the existing doctest comments in the template (the lines starting with >>> and the results underneath).

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

## Description

Template: HW2.template.hs

In this assignment, 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.

Download the above template and rename it. For each undefined function in the template, you should:

1. Write the appropriate type of the function.
2. Implement the function.

NOTE: For the purposes of this 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.