OCAML Final

studied byStudied by 31 people
0.0(0)
get a hint
hint

A value is an expression (values are a subset of expressions).

1 / 47

Tags and Description

48 Terms

1

A value is an expression (values are a subset of expressions).

True

New cards
2

In OCaml, functions taking a string as an argument always produce a string as the result.

False

New cards
3

In OCaml, floats are represented as the ratio of two integers.

False

New cards
4

Structurally recursive functions may diverge on some inputs.

False

New cards
5

An expression is

a computation that evaluates to a value.

New cards
6

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.

New cards
7

In OCaml, floats have infinite precision.

False

New cards
8

if 0 then "a" else "b"

is not well-typed.

New cards
9

Which of the following are values (select all that apply)?

17 false "hello world"

New cards
10

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

New cards
11

How many distinct values? type typeA = | ACon1 | ACon2 of bool * bool

5

New cards
12

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)}

New cards
13

Lists in OCaml are mutable.

False

New cards
14

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)}

New cards
15

A function f : A → B is surjective iff

∀ y ∈ B, ∃ x ∈ A, f(x) = y

New cards
16

How many distinct values? type typeC = | CCon of bool * typeC

0

New cards
17

Let A and B be sets defined by A = {0, 1}, B = {0, 2}. Then, the intersection A ∩ B =

{0}

New cards
18

A function f : A → B is injective iff

∀ x y ∈ A, f(x) = f(y) ⇒ x = y

New cards
19

The following OCaml type has how many distinct values? type typeB = | BCon1 of bool | BCon2 of bool * typeB

New cards
20

Let A and B be sets defined by A = {0, 1}, B = {0, 2}. Then, the union A ∪ B =

{0, 1, 2}

New cards
21

Lists in OCaml can only contain elements of type int or string.

False

New cards
22

'fold_right' (right-associative fold) on lists can be implemented using only 'map' (i.e., 'map' is more general than 'fold_right').

False

New cards
23

The 'map' operation on lists can be implementing with 'fold_right' (right-associative fold) (i.e., 'fold_right' is more general than 'map').

True

New cards
24

((A * B) → C) ∼ (A → (B → C)) for all types A, B, and C (where '∼' denotes type equivalence)

True

New cards
25

(A * (B → C)) ∼ (A → (B → C)) for all types A, B, and C (where '∼' denotes type equivalence)

False

New cards
26

In OCaml, functions can be compared for structural equality by reference.

False

New cards
27

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

New cards
28

Identify the correct structural and physical equality operators.

structural equality =

structural inequality <>

physical equality ==

physical inequality !=

New cards
29

let rec size x = match x with | [] -> 0 | h :: t -> 1 + (size t)

False

New cards
30

let rec list_gen i j acc = if i > j then acc else list_gen i (j-1) (j :: acc)

True

New cards
31

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]

New cards
32

Monads provide an abstraction of effects, and help to make sure that effects happen in a controlled order.

True

New cards
33

The name “monad” comes from the mathematical field of category theory, which studies abstractions of mathematical structures.

True

New cards
34

A promise is a mechanism for lazy evaluation.

False

New cards
35

Valid States of a Promise

Resolved Rejected Pending

New cards
36

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).

New cards
37

The fundamental operations of an OCaml monad are:

Return and Bind

New cards
38

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

New cards
39

It is possible for recursive functions to diverge (loop forever).

True

New cards
40

Functions cannot be compared for structural equality.

True

New cards
41

Functions cannot be compared for physical equality.

False

New cards
42

In OCaml, all the elements of a list must have the same type.

True

New cards
43

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.

New cards
44

Sequence

Mathematically is an infinite list.

New cards
45

Lazy Evaluation

Do not compute until specifically demanded.

New cards
46

Interleaving

rapidly switch back and forth between computations.

New cards
47

Parallelism

use hardware that is capable of performing two or more computations literally at the same time.

New cards
48

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.

New cards

Explore top notes

note Note
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 8 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 10 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 3 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 36 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 9 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 182 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard92 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard23 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard42 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard28 terms
studied byStudied by 295 people
Updated ... ago
5.0 Stars(2)
flashcards Flashcard100 terms
studied byStudied by 9 people
Updated ... ago
5.0 Stars(5)
flashcards Flashcard76 terms
studied byStudied by 17 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard153 terms
studied byStudied by 3 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard256 terms
studied byStudied by 175 people
Updated ... ago
5.0 Stars(3)