Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hi, I'm writing a program in Ocaml which is a tail recursive version of the power function. The function is pow_tl : int -> int
Hi,
I'm writing a program in Ocaml which is a tail recursive version of the power function. The function is pow_tl : int -> int -> int -> int and takes as input a base n, and exponent k, and an accumulator to build up the result. I have written this code:
let pow_tl n k = let rec aux n k acc = if k == 0 then 1 else if k == 1 then n else n * aux n (k - 1) in aux n k 1
But I get the error, "This expression has type 'a -> int but an expression was expected of type int" and I'm not sure why. Any help would be appreciated!
Thanks!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started