Reputation: 91
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
Upvotes: 0
Views: 372
Reputation: 36339
|otherwise = n * power'' n k-1
this is
|otherwise = (n * power'' n k)-1
and hence you recurse with the same arguments forever.
Upvotes: 5