Programming Languages Practice Test I, Exams of Programming Languages

A practice test for Programming Languages course in Fall 2016. It is 4 pages long and includes short-answer questions. The test is closed books, notes, papers, friends, neighbors, etc. The first question is about first-class functions, the second question is about an ML program that violates the value restriction and its equivalent program, and the third question is about implementing a function filter in ML syntax without calling any built-in higher-order functions.

Typology: Exams

2015/2016

Uploaded on 05/11/2023

agrata
agrata 🇺🇸

4

(7)

258 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Programming Languages [Fall 2016]
Practice Test I
NAME: ______________________________________________________
Instructions:
1) This test is 4 pages in length.
2) You have 75 minutes to complete and turn in this test.
3) Short-answer questions include a guideline for how many sentences to write. Respond
in complete English sentences.
4) This test is closed books, notes, papers, friends, neighbors, etc.
5) Use the backs of pages in this test packet for scratch work. If you write more than a
final answer in the area next to a question, circle your final answer.
6) Write and sign the following: “I pledge my Honor that I have not cheated, and will not
cheat, on this test.”
_______________________________________________________________________
_______________________________________________________________________
Signed: ______________________________________________
pf3
pf4

Partial preview of the text

Download Programming Languages Practice Test I and more Exams Programming Languages in PDF only on Docsity!

Programming Languages [Fall 2016]

Practice Test I

NAME: ______________________________________________________

Instructions:

  1. This test is 4 pages in length.

  2. You have 75 minutes to complete and turn in this test.

  3. Short-answer questions include a guideline for how many sentences to write. Respond in complete English sentences.

  4. This test is closed books, notes, papers, friends, neighbors, etc.

  5. Use the backs of pages in this test packet for scratch work. If you write more than a final answer in the area next to a question, circle your final answer.

  6. Write and sign the following: “I pledge my Honor that I have not cheated, and will not cheat, on this test.”



Signed: ______________________________________________

What are first-class functions? [1-2 sentences]

  1. [10 points] a) Provide an example of an ML program that violates the value restriction.

b) Rewrite your example from Part (a) into an equivalent program that does not violate the value restriction.

  1. [25 points] a) Implement a function filter that takes (in curried form) a function F and a list L of triples. Function F must take a triple and return a bool. Function filter returns a list containing only those triples in L for which F returns true. Use ML syntax in your implementation (including pattern matching, anonymous variables, and as-bindings when appropriate). Do not call any built-in higher-order functions (like map , foldl , or foldr ) in your implementation.

b) What type does filter have?

a) Define inference rules for greater-than and less-than judgments over natural numbers. The judgment forms are: N 1 >N 2 and N 1 <N 2. Recall that N 1 and N 2 , being natural numbers, adhere to our definition of natural numbers (N nat), as discussed in class.

b) Using your definitions of greater-than and less-than, prove that for all natural numbers N 1 and N 2 : (N 1 >N 2 ) if and only if (N 2 <N 1 ).

c) Prove that your less-than operator is transitive , i.e., for all natural numbers N 1 , N 2 , and N 3 : if N 1 <N 2 and N 2 <N 3 then N 1 <N 3.