0

Here is one implementation of power function in Haskell. But I have stack overflow error. No idea how to fix

power''::Integer->Integer->Integer
power'' _ 0=1
power'' 1 _=1
power'' n k
    |even k = power'' (n*n)  (k `div` 2)
    |otherwise = n * power'' n k-1

2 Answers 2

5
|otherwise = n * power'' n k-1

this is

|otherwise = (n * power'' n k)-1

and hence you recurse with the same arguments forever.

Sign up to request clarification or add additional context in comments.

1 Comment

well I have to |otherwise = n * power'' n (k-1)
0

--Found my problem

 |otherwise = n * power'' n (k-1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.