Homework 6

Please read chapter 10: More on Lists and chapter 11: Design by Composition in the textbook. Also read section 5 (Local definitions) and 7 (Advanced types) in the Typed Racket Notes. We've skipped section 6 for now, but we'll come back to them. Local definitions appear in section 16.2 in the textbook. You may look ahead at that section now, if you like; however there are several examples there that involve things you have not learned yet, so you probably won't be able to understand all of it.

Be sure to include type, purpose, definition and tests for all functions.

Include the following at the top of your homework:

#lang typed/racket

(require "../include/uchicago151.rkt")
(require typed/test-engine/racket-tests)
And include (test) at the bottom of your homework.

Problem 1

Write following functions on lists.

Problem 2

We define the following data type for lists of coins:

(define-type Coin (U "Dollar" "Quarter" "Dime" "Nickel" "Penny"))
This creates a type, Coin that can have only five values. Those values are the strings "Dollar", "Quarter", "Dime", "Nickel", and "Penny". You may recall that we can compare two strings with the string=? function.

Practice

If these functions are difficult, please spend time on the reading. The book has a lot of good exercises and examples that you should use for practice. Understanding lists in particular and recursive data structures in general is very important.

Submit your work in your repository in hw6/hw6.rkt by noonMonday, July 3.