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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.