Due: Wed, Oct 4, 10:59pm
How to Submit
Submit a single file named
Your submission must compile without errors in GHCi. Put all non-working parts of your solution in comments.
Please preserve the existing
doctestcomments 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.
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:
- Write the appropriate type of the function.
- 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.