7.3.0.3

Lab 4

1Notes on Testing and Language Choice

First: unless you’re feeling really gung-ho, do this lab in #lang racket, not in #lang typed/racket.

Second: you can’t check equality of functions directly, which makes test cases difficult. When an exercise asks you to produce a function, the test case should go ahead and supply inputs to the function, so that you can test equality of numbers rather than functions.

2Applying Lambdas

What should this expression produce?

((lambda (x) (+ x 2)) 3)

Try running it. Did it produce what you expected?

Next: what should this expression produce?

 ((lambda (f g) (f (g 3))) (lambda (x) (+ x 3)) (lambda (x) (* x 2)))

Try to figure it out first! Then evaluate it.

Develop the curried-add function. It takes a number ’a’ and returns a function that takes a number ’b’ and returns a+b. In other words, it has the type

(number -> (number -> number))

... where (t1 -> t2) is the type of a function that takes a t1 and produces a t2.

4curry2

Develop the curry2 function; it takes a function of two arguments, and produces a function that takes one argument and produces a function that takes one argument and produces the result of calling the input function on the two given arguments. In other words, it has the type

(All (a b c) ((a b -> c) -> (a -> (b -> c))))

... for types a,b, and c. You will need lambda for this.

5curry3

Develop the curry3 function; it takes a function of three arguments, and produces a function that takes one argument and produces a function that takes one argument and produces a function that takes one argument and produces the result of calling the input function on the three given arguments. In other words, it has the type

(All (a b c d) ((a b c -> d) -> (a -> (b -> (c -> d)))))

... for types a,b,c, and d. You will need lambda for this.

6contains?

Develop the contains? function, that consumes a list and a symbol and returns true exactly when the symbol occurs in the list.

Use curry2 and contains? to develop in-list-many?, that consumes a source list of symbols and a list of query symbols, and returns a list of booleans indicating for the corresponding element of the query list whether it occurs in the source list. Use the built-in function map. This function should be a one-liner.