Send a link to your students to track their progress
48 Terms
1
New cards
A value is an expression (values are a subset of expressions).
True
2
New cards
In OCaml, functions taking a string as an argument always produce a string as the result.
False
3
New cards
In OCaml, floats are represented as the ratio of two integers.
False
4
New cards
Structurally recursive functions may diverge on some inputs.
False
5
New cards
An expression is
a computation that evaluates to a value.
6
New cards
A list value in OCaml can be any of the following (select all that apply):
-a cons cell containing a data element and the rest of the list. -the empty list -a cons cell containing a data element and the rest of the list.
7
New cards
In OCaml, floats have infinite precision.
False
8
New cards
if 0 then "a" else "b"
is not well-typed.
9
New cards
Which of the following are values (select all that apply)?
17 false "hello world"
10
New cards
OCaml evaluates a function call by evaluating the function's body after substituting the values of the arguments for the function's formal parameters.
True
11
New cards
How many distinct values? type typeA = | ACon1 | ACon2 of bool * bool
5
12
New cards
Let A and B be sets defined by A = {0, 1}, B = {0, 2}. Then, the cartesian product A × B =
{(0, 0), (0, 2), (1, 0), (1, 2)}
13
New cards
Lists in OCaml are mutable.
False
14
New cards
Let A and B be sets defined by A = {0, 1}, B = {0, 2}. Then, the disjoint union (as defined in class) A ∪⁺ B is:
{(0, 0), (0, 1), (1, 0), (1, 2)}
15
New cards
A function f : A → B is surjective iff
∀ y ∈ B, ∃ x ∈ A, f(x) = y
16
New cards
How many distinct values? type typeC = | CCon of bool * typeC
0
17
New cards
Let A and B be sets defined by A = {0, 1}, B = {0, 2}. Then, the intersection A ∩ B =
{0}
18
New cards
A function f : A → B is injective iff
∀ x y ∈ A, f(x) = f(y) ⇒ x = y
19
New cards
The following OCaml type has how many distinct values? type typeB = | BCon1 of bool | BCon2 of bool * typeB
∞
20
New cards
Let A and B be sets defined by A = {0, 1}, B = {0, 2}. Then, the union A ∪ B =
{0, 1, 2}
21
New cards
Lists in OCaml can only contain elements of type int or string.
False
22
New cards
'fold_right' (right-associative fold) on lists can be implemented using only 'map' (i.e., 'map' is more general than 'fold_right').
False
23
New cards
The 'map' operation on lists can be implementing with 'fold_right' (right-associative fold) (i.e., 'fold_right' is more general than 'map').
True
24
New cards
((A * B) → C) ∼ (A → (B → C)) for all types A, B, and C (where '∼' denotes type equivalence)
True
25
New cards
(A * (B → C)) ∼ (A → (B → C)) for all types A, B, and C (where '∼' denotes type equivalence)
False
26
New cards
In OCaml, functions can be compared for structural equality by reference.
False
27
New cards
let rec filter f lst = match lst with | [ ] -> [ ] | x :: r -> if f x then x :: filter f r else filter f r
What is the output of filter when "f x" is false for every x in the input list?
the empty list
28
New cards
Identify the correct structural and physical equality operators.
structural equality =
structural inequality <>
physical equality ==
physical inequality !=
29
New cards
let rec size x = match x with | [] -> 0 | h :: t -> 1 + (size t)
False
30
New cards
let rec list_gen i j acc = if i > j then acc else list_gen i (j-1) (j :: acc)
True
31
New cards
let rec list_gen i j acc = if i > j then acc else list_gen i (j-1) (j :: acc) ;;
list_gen 1 6 [ ]
[1; 2; 3; 4; 5; 6]
32
New cards
Monads provide an abstraction of effects, and help to make sure that effects happen in a controlled order.
True
33
New cards
The name “monad” comes from the mathematical field of category theory, which studies abstractions of mathematical structures.
True
34
New cards
A promise is a mechanism for lazy evaluation.
False
35
New cards
Valid States of a Promise
Resolved Rejected Pending
36
New cards
Regardless of whether a promise was rejected, a promise can be resolved once and only once.
True MAYBE (False because if it is rejected it cannot be resolved).
37
New cards
The fundamental operations of an OCaml monad are:
Return and Bind
38
New cards
An OCaml sequence is a data structure that can contain an infinite amount of elements regardless the amount of memory available on a computer.
True
39
New cards
It is possible for recursive functions to diverge (loop forever).
True
40
New cards
Functions cannot be compared for structural equality.
True
41
New cards
Functions cannot be compared for physical equality.
False
42
New cards
In OCaml, all the elements of a list must have the same type.
True
43
New cards
Memoization
optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again.
44
New cards
Sequence
Mathematically is an infinite list.
45
New cards
Lazy Evaluation
Do not compute until specifically demanded.
46
New cards
Interleaving
rapidly switch back and forth between computations.
47
New cards
Parallelism
use hardware that is capable of performing two or more computations literally at the same time.
48
New cards
nondeterministic
the order in which operations occur cannot necessarily be known ahead of time.
Purely functional programs make nondeterminism easier to reason about, because evaluation of an expression always returns the same value no matter what.