Question: Problem 21 Recall that the composition of two functionsf and g-- is h(x) = f(g(x)). Of course, the range of g must be a subset
Problem 21
Recall that the composition of two functionsf and g-- is h(x) = f(g(x)). Of course, the range of g must be a subset of the domain of f. Implement a generic compose combinator.
Problem 22
Use recursion and your solution to problem 1 to implement the self-composition iterator combinator:
def selfIter[T](f: T=>T, n: Int) = f composed with itself n times.
Test your function with:
def inc(x: Double) = x + 1
def double(x: Double) = 2 * x
Note:
selfIter(f, 0)= id where id(x) = x.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
