Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

Describe briefly the function of the GAO.

Answered: 1 week ago

Question

Trace the history of organizational behavior.

Answered: 1 week ago