CS 334: HW 4

Instructions

This homework has two types of problems:

  • Self Check: You are strongly encouraged to think about and work through these questions, but you will not submit answers to them.

  • Problems: You will turn in answers to these questions.

Reading

  • (Required) Read Mitchell, Chapter 5.

  • (As necessary) Read ML references, as needed for the programming questions.

Problems

1. ML Map for Trees (10 pts)

Mitchell, Problem 5.4

You are not required to submit a program file for this question, but you may want to double check your answer by running your solution. If you do, be sure to include

Control.Print.printDepth:= 100;

at the top of your file, so that datatypes print completely.

2. ML Reduce for Trees (10 pts)

Mitchell, Problem 5.5

You are not required to submit a program file for this question, but you may want to double check your answer by running your solution.

3.Currying (10 pts)

Mitchell, Problem 5.6

You are not required to submit a program file for this question, but you may want to double check your answer by running your solution.

Note that you MUST explain why the equations hold. One way to do this is to apply both sides of each equation to the same argument(s) and describe how each side evaluates to the same term. For example, show that

\tt UnCurry(Curry(f)) (s,t) = f (s,t)

and

\tt Curry(UnCurry(g))~s~t = g~s~t

for any \tt s and \tt t.

4. Type Inference (10 pts)

Type Inference Checker

Triceratypes is a Type Inference Checker to help you practice the type inference algorithm. You can find it on the CS334 website here.

Infer the type for the following function using our type inference algorithm:

fun f(g,h) = g(h) + 2;

Parse Tree for f

5. Type Inference and Bugs (10 pts)

What is the type of the following ML function?

fun append(nil, l) = l
  | append(x::l, m) = append(l,m);

Write one or two sentences to explain succinctly and informally why append has the type you give. This function is intended to append one list onto another. However, it has a bug. How might knowing the type of this function help the programmer to find the bug?

Submitting Your Work

Submit your answers to the GradeScope assignment named, for example, "HW 0". It should:

  • be clearly written or typed,
  • include your name and HW number at the top,
  • list any students with whom you discussed the problems, and
  • be a single PDF file, with one problem per page.

You will be asked to resubmit homework not satisfying these requirements. Please select the pages for each question when you submit.