Exercises
Consider the following curried function:
fun composeUnaryIntOps (f:int -> int) (g:int -> int) = fn x => f (g x);
Using this function along with anonymous functions and
(possibly named) higher-order functions you devise yourself,
define:
- A function negateAndInc that negates and then
adds 1 to its single parameter.
- A function addThenMult with two parameters
a and m, that produces a single-parameter
function that first adds a and then multiplies m to its
parameter.
- A function twice that takes a binary function
binOp and an operand value opVal, and returns
a single-parameter function that takes a value k and
- Applies binOp to k and opVal
- Applies binOp to the result and opVal
- A function that, given two unary functions, applies them to
alternating elements of an integer list. In other words, it
should apply f to the first element, g to the second element, f
to the third element, etc.
- Rewrite the answer to the previous problem using the
reduce function from lecture.
Keunwoo Lee
Last modified: Wed Apr 25 23:07:50 PDT 2001