For the next five items, specify the value of the given expression,
assuming the following definitions
fun s n = n+1;
fun compose(f,g) = fn x => f(g(x));
fun twice(f,y) = f(f(y));
fun ctwice f y = f(f(y));
fun sum(g,0) = g(0)
|sum(g,n) = g(n) + sum(g,n-1);
(fn f => (fn x=>f(f(f x)))) s 1
- (A) 1
- (B) 2
- (C) 3
- (D) 4
- (E) 5
twice(compose(s,s),0)
- (A) 0
- (B) 2
- (C) 4
- (D) 6
- (E) 8
sum(fn x=>x*x-2,3)
- (A) 0
- (B) 2
- (C) 4
- (D) 6
- (E) 8
compose(fn x=>x+1,fn y=>y-1)(4)
- (A) 0
- (B) 2
- (C) 4
- (D) 6
- (E) 8
twice(ctwice,s) 2
- (A) 0
- (B) 2
- (C) 4
- (D) 6
- (E) 8
Which of the following is an inductive definition of natural numbers:
- (A) 0,1,2,3,...
- (B) 0 is a natural number; if n is a natural number then n+1 is
a natural number, for all n> 0
- (C) all integers greater than or equal to 0
- (D) n is a natural number, for all n> 0
- (E) {n | n> 0}
Consider two definitions of factorial:
fun fact 0 = 1 local
|fact n = n * fact(n-1); fun tfact(0,k) = k
|tfact(n,k) = tfact(n-1,n*k)
in
fun fastfact n = tfact(n,1)
end;
We can prove fact(n) = fastfact(n) by applying mathematical
induction (over n) to what property:
- (A) fact(n) = tfact(n,1)
- (B) k*fact(n) = tfact(n,k)
- (C) fact(n) = fastfact(n)
- (D) fact(n) = tfact(n,k)
- (E) fact(n*k) = tfact(n,k)
Consider the following Standard ML function:
fun petruchio(nil,nil) = true
|petruchio(x::xs,y::ys) = petruchio(xs,ys)
|petruchio(xs,ys) = false
What does this function do:
- (A) test whether two lists are identical
- (B) test whether two lists are of the same type
- (C) test whether two lists are the same length
- (D) test whether two lists contain the same elements
- (E) test whether it is given two lists as arguments
The language Standard ML is higher order because
- (A) it is an upper-class language
- (B) it does not contain assignment
- (C) it is purely functional
- (D) it has a well-defined semantics
- (E) functions can be passed as values and returned as results
The Penn State women's volleyball team
- (A) was national champions last year
- (B) is fun to watch
- (C) has the longest home winning streak
- (D) plays in Rec Hall
- (E) all of the above