Question 1 @ 2024-03-12 18:25
If S
is a subtype of T
, is (Boxof S)
a subtype of (Boxof T)
?
-
Yes, since
S
can be safely subsituted withT
-
Yes, since
T
can be safely subsituted withS
-
Yes, since
Boxof
works the same asListof
-
No, it’s the other way:
(Boxof T)
is a subtype of(Boxof S)
-
No, since
Boxof
is an idempotent multivariadic type constructor -
No, the type argument of
Boxof
is both covariant and contravariant -
No, because
S
andT
are arbitrary independent types
Question 2 @ 2024-03-12 18:28
Consider the following typed definition:
(: blah : (Rec T (List String (U Number T))))
(define blah (list "blah" 1))
(define blah (list "blah" 1))
What is the type of (second blah)
?
-
Number
- Whatever Typed Racket calls “a small positive integer”
-
(U Number T)
-
(U Number (Rec T (List String (U Number T))))
-
(Rec T (U Number T))
- It’s a polymorphic type, so impossible to have a specific answer
Question 3 @ 2024-03-12 18:31
You’re given a language that fulfils the following test:
(test (map (+ 2) '(1 2 3)) => '(3 4 5))
Which of the following is a true statement about this language?
- It cannot be compiled
- It is dynamically scoped
- It is Schlac
- It is Schlac, extended by all of the encodings we’ve seen in class
-
It cannot be a statically typed language (like
#lang pl
) - It is an auto-curried language
Question 4 @ 2024-03-12 18:34
When we discussed extending TOY with a set!
expression for mutations, we made
it return a bogus value.
What is the advantage of doing this?
-
It allows you to chain
set!
assignments. - It allows use of the old value that is overwritten.
- It allows side effects within an expression.
- It has less overhead both in the implementation code.
- It encourages being explicit about return values, resulting in more robust code.
- It is a better choice for a purely functional language.
Question 5 @ 2024-03-12 18:37
Continuing with the mutation-extended Toy language, what would the following
evaluate to, if we make set!
return the newly assigned value instead?
{bind {x 4}
{bind {y {set! x 3}}
{+ {set! x {+ x y}}
x}}}
{bind {y {set! x 3}}
{+ {set! x {+ x y}}
x}}}
- 6
- 7
- 9
- 10
- 12
- 14
- Syntax error
- Runtime error