Programming Languages Exam 2 review

Programming Languages Exam 2 review

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

Consider the following code line datatype 'data tree = Empty | Node of 'data tree 'data 'data tree; val treeEmpty = Empty; val tree2 = Node(Empty,2,Empty); val tree123 = Node(Node(Empty,1,Empty),2,Node(Empty,3,Empty)); Which of the following is NOT true? a. val treeEmpty = Empty : 'a tree b. val tree2 = Node (Empty,2,Empty) : int tree c. val tree123 = Node(Node(Empty,1,Empty),2,Node(Empty,3,Empty)) : int tree d. val tree123 = Node(1, 2, 3): int tree

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (25)

Section 1

(25 cards)

Consider the following code line datatype 'data tree = Empty | Node of 'data tree 'data 'data tree; val treeEmpty = Empty; val tree2 = Node(Empty,2,Empty); val tree123 = Node(Node(Empty,1,Empty),2,Node(Empty,3,Empty)); Which of the following is NOT true? a. val treeEmpty = Empty : 'a tree b. val tree2 = Node (Empty,2,Empty) : int tree c. val tree123 = Node(Node(Empty,1,Empty),2,Node(Empty,3,Empty)) : int tree d. val tree123 = Node(1, 2, 3): int tree

Front

d

Back

What is the output? foldr (op +) 0 [1,2,3,4]; a. error b. val it = 10 : int c. val it = [1,2,3,4] : int list

Front

b

Back

ML's syntax keeps types and expressions separated T F

Front

T

Back

A type with type variables is a _________ a. unitype b. polytype c. multitype d. monotype

Front

b

Back

In ML, you can add a parameter of any type to a data constructor, using the keyword ______ a. of b. struct c. typedef d. def

Front

a

Back

A function that takes a function as a parameter or returns a function value has order n+1, where n is the order of its highest-order parameter or returned value T F

Front

T

Back

Consider the following function fun merge (nil, ys) = ys | merge (xs, nil) = xs | merge (x :: xs, y :: ys) = if (x < y) then x :: merge (xs, y :: ys) else y :: merge(x :: xs, ys); What is the result for the following statement: merge ([1, 2, 3], [4, 5, 6]); a. val it = [1, 4, 2, 5, 3, 6 ] : int list b. val it = [1, 2, 3, 4, 5, 6] : int list c. val it = [1, 2, 3, 4, 5, 6] : list d. val it = [1, 3, 5, 2, 4, 6] : int list

Front

b

Back

C++, permit the programmer to overload function names True False

Front

T

Back

Consider the following code lines: datatype 'element mylist = NIL | CONS of 'element * 'element mylist; CONS(1, CONS(2, NIL)); Which of the following is true? a. val it = (1, 2) : int mylist b. val it = CONS (1,CONS (2,NIL)) : mylist c. val it = CONS (1,CONS (2,NIL)) : int mylist d. val it = [1, 2]: int list

Front

c

Back

Which of the following is not a ML pattern? a. A cons of patterns b. .... c. A constant d. _

Front

b

Back

Given datatype day = Mon | Tue | Wed | Thu | Fri | Sat | Sun; and fun isWeekDay Sat = false | isWeekDay Sun = false | isWeekDay _ = true; What is the value of isWeekDay Mon; a. false b. true c. Error

Front

b

Back

How many blocks it contains? case x of (a,0) => a | (_,b) => b 4 1 2 3

Front

c

Back

Which of the following have the same effect as: fun f x = x * x; val f => fn x = x* x; val f = x => x * x; val fn x => x* x; val f = fn x => x * x;

Front

d

Back

In C++, which f gets called for f('a', 'b') ? a. void f(int x, char y) { ... } b. void f(char x, int y) { ... } c. Compile error due to ambiguous

Front

c

Back

What is the output? ~ 3 + 5; a. val it = ~2 : int b. val it = ~8 : int c. val it = 2 : int d. val it = 8 : int

Front

c

Back

Consider the following halve function: fun halve nil = (nil, nil) | halve [a] = ([a], nil) | halve (a :: b :: cs) = let val (x, y) = halve cs in (a :: x, b :: y) end; What is the result of the following statement? halve [1]; A. val it = ([], [1]) : int list * int list b. val it = ([], [1]) : int list * int c. val it = ([1], []) : int list * int list d. val it = ([1], []) : int * int list

Front

c

Back

Given fun g a = fn b => fn c => a+b+c; What is the type of g? (int -> int) -> (int -> int) int -> int -> int -> int int int int -> int int * int -> int -> int

Front

b

Back

Which of the following defines the <match> in ML? ::= <rule> '|' <match> ::= <rule> '|' <rule> ::= <rule> ::= <rule> | <rule> '|' <match>

Front

d

Back

What is the result of the following: let val x = 1 val y = 3 in x + y end; a. val it = 3 : int b. val it = 1 : int c. val it = 2 : int d. val it = 4 : int

Front

d

Back

In C++, the namespace specifies the visibility of its components T F

Front

T

Back

Based on code line datatype 'a option = NONE | SOME of 'a; val x = SOME 4; Which of the following is true? a. val x = SOME 4 : int b. val x = 4 : int option c. val x = SOME 4 : int option d. val x = SOME 4 : option

Front

c

Back

To avoid ambiguous, there is only one definition for a given name. T F

Front

F

Back

The question: whether a given occurrence of a name is in the scope of a given definition? If the questios is answered at compile time, it is called __________ scoping a. static b. dynamic c. systematic d. traditional

Front

a

Back

what is the output of following map (op +) [(1,2),(3,4),(5,6)]; a. val it = [3,7,11] : int list b. val it = [9, 12] : int list c. error d. val it = [3,7,11] : int int int

Front

a

Back

Which of the following pattern in ML matches anything? a. ... b. _ c. ~ d. ()

Front

b

Back