Homework #1
Due: Wed, Jan 13
How to Submit
Assign yourself to a “Group” in Canvas. Select “People” from the menu, then select the “Groups” tab. Click “Join” on a group whose name starts with “HW1”.
You must coordinate with your team members to all join the same group. When choosing a group, please use the smallest available group number.
Do not add yourself to a group unless you have already coordinated and everyone has agreed to be in a group together.
Upload a single file named
HW1.hs
for your team for this assignment in Canvas. Only one team member needs to upload the file.Your file must contain the names and ID numbers of each member of your group in a comment at the top of your file. This is to ensure that nobody changed the composition of your group.
Your file must compile without errors in GHCi. If some of your code does not work, comment it out. If your code does not compile, the TAs will evaluate it harshly!
Do not change the existing doctest comments in the template (the lines starting with
>>>
and the results underneath). However, you are free to add your own doctest comments in addition to the ones that are there. The TAs will grade using both doctest and manual inspection of your file. If needed, they may also load your file in GHCi to run additional tests.If you can’t solve a problem, you can get partial credit by describing in comments what you tried and where you got stuck. Often times, writing this out helps you get unstuck!
Description
The goal of this assignment is to help you learn the basics of programming in Haskell: data types, functions, pattern matching, and recursion.
In this assignment, you will define several functions for querying, generating, and manipulating binary trees of integers. Some of the problems will also require knowing about binary search trees.
Download this template (HW1.template.hs), rename it to HW1.hs
, and enter your solutions directly in the file.
For each undefined
function in the template, you should:
- Write the appropriate type of the function.
- Implement the function.
The comment preceding each function gives a brief English description of what the function should do. Additionally, each comment contains doctest
examples that illustrate the intended behavior of the function. You can use these examples both to help understand the intended behavior of the function, and as unit tests using the doctest
tool demonstrated in class. Feel free to add more examples to improve your test coverage.