Assignment 3: Higher-Order Functions, Algebraic Data Types, and Pattern Matching in Swift


Due Tuesday, May 4 at 11:59 PM

Goals for This Assignment

By the time you have completed this work, you should be able to:

Provided files:

Step-by-Step Instructions

Step 1: Get Swift Working

For this assignment, you'll be using Swift. You can either install Swift from this link, or run it in the browser here. Binaries are available for Ubuntu Linux and Mac OS X. Exactly which method you use doesn't matter; it will work the same either way.

Step 2: Implement a Singly-Linked List

A significant of code has been provided in main.swift, including a test suite of significant size. As with assignment 1, you are tasked with writing a singly-linked list. However, this time around, you'll be doing this in Swift. Instead of using dynamic dispatch to select between cons and nil behavior, you'll be using pattern matching via switch. Additionally, you'll also be defining key list-based operations which work with higher-order functions, namely filter and map. The comments in the file provide further details. Note that the tests themselves are a rich source of information, both in terms of defining what you need to implement (i.e., they serve as a specification), and how Swift works.

Step 3: Turn in Your Code Using Canvas

Log into Canvas, and go to the COMP 333 class. Click “Assignments” on the left pane, then click “Assignment 3”. From here, you need to upload the following files:

In addition, if you collaborated with anyone else, be sure to download collaborators.txt and write the names of the people you collaborated with in the file, one per line. Please submit this file along with the other files.

You can turn in the assignment multiple times, but only the last version you submitted will be graded.