You can use one handwritten 8.5x11 notes sheet. Please put your name on your sheet, and we will be collecting them at the end of the exam. Good Luck!
eval : expr -> expr
. Since
this language is so tiny there are not many cases to consider and
the interpreter won't take that long to write out.
You can assume and use the following datatypes:
type ident = Ident of string type expr = Var of ident | Function of ident * expr | Appl of expr * expr
(Fun x -> Fun y -> y)((Fun z -> z z)(Fun z -> z z)) ==> Fun y -> yin Fb--N, whereas in Fb-- it would not compute to any value.
τ ::= τ -> τbut this completely fails in a really bad way; why?
τ ::= τ -> τ | 'aAn example typing would be program |- (Fun x : 'a -> x)(Fun y : 'b -> y) : 'a. Write out all of the type rules for TFb--.
Abort
control
operator causes a program to immediately
terminate and return a value. For this question we will add abort to the very simple language Fb-- in question 1, giving a new language Fb--Ab. It will include
a new syntax form
Abort(e)
which when executed returns the value of
e
and quits. As an example, (Fun x -> (Fun z -> z))(Abort((Fun y -> y)) ==> Fun y -> yIf we extended abort to full FbAb we would also have an example like 7 + Abort(1 + 3) ==> 4.
For this question, write all of the operational semantics rules for Fb--Ab. Feel free to include rules from your answer to question 1 by referring to them.
Let r = {a = 5; c = 6} In Let rr = {b = 7; c = True } In Let rrr = r @ rr In rrr.c ==> TrueNotice in particular from this example how if a field is in both records the appended record takes the field from the right record. This is also a functional operation, neither r nor rr was changed by the @ operation.
For this question we are just going to explore some programming benefits of having such an append operation. With record append, it is much simpler to encode inheritance or even object extension. For this question, encode a simple Point object as a record with integer fields x, y and methods magnitude, isZero and then define an extension to it (its the same object but with more goodies added) called MorePoint which includes an additional method isNotZero which simply negates the result of calling isZero on the object. Concretely, the program
Let Point = ... In Let MorePoint = ... (use @ and Point, don't repeat code here) ... In MorePoint.isNotZero MorePoint {}should appropriately execute. All you need to write for your answer is how Point and MorePoint are defined.
# type rt = {mutable a : int; mutable b : int};; type rt = { mutable a : int; mutable b : int; } # let r = { a = 5; b = 7};; val r : rt = {a = 5; b = 7} # r.b <- 4;; - : unit = () # r;; - : rt = {a = 5; b = 4} # r.b;; - : int = 4For this question you are to define a language with mutable records, FbmR. For simplicity, we will assume all fields in a record are mutable. Compared to FbR you only need to support the additional field mutation syntax e.l <- e for l a record label.