Homework 9

Please read chapter 17 Nameless Functions, chapter 18 Summary, the sections labelled Intermezzo: Scope and Abstraction, Scope, and Pattern Matching and chapter 19 The Poetry of S-expressions in the textbook. You can ignore the section labelled ISL for Loops - we won't be learning that in this class. Also read all of chapter 6 and 8 in the Typed Racket Notes.

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)

You will also need the following batch of data structures:

(define-struct Point
  ([x : Real]
   [y : Real]))

(define-struct Line
  ([m : Real]
   [b : Real]))

(define-struct Interval
  ([min : Real]
   [max : Real]))

And include (test) at the bottom of your homework.

Problem 1

Write the following functions using the built-in functions map, foldr, foldl, and filter, providing appropriate function arguments to these higher-order functions. You may use one, or more, of the listed functions to construct your solution; but, for credit, you must use at least one of these functions, rather than writing a recursive solution that directly processes a list.

Some of the problems refer to custom data types; please see above.

Problem 2

Rewrite the built in function reverse. Hint: you may want to use the append function.

Problem 3

Write the following higher-order function.

Practice

If you still have trouble with using empty, cons, first, rest, and empty? to process lists, you should also do the questions in this assignment using those instead of using build-list, filter, map, foldr, and foldl.

If you still have trouble with using build-list, filter, map, foldr, and foldl to process lists, you should try to do all of the previous homework questions using those instead of empty, cons, first, rest, and empty?.

Submit your work in your repository in hw9/hw9.rkt by noon Monday, July 10.