a. Write a tail-recursive version of the upto function mentioned in the lecture note, call it tailUpto :: Int->Int->[Int]->[Int]
. For examples:
tailUpto 3 8 [1,2] = [3,4,5,6,7,8,1,2]
tailUpto 8 3 [1] = [1]
In other words, upto m n = tailUpto m n []
.
b. Write a tail-recursive version of the fib
function to compute the nth number in the Fibonacci sequence. Specifically, define the tailFib function with two accumulating parameters
tailFib :: Int->Int->Int->Int
so that fib n = tailFib n 0 1
.