1
votes

I was trying to implement the following function in Haskell

p :: Float -> Int -> Float
p x 0 = 1
p x n = x^(p x (n-1))

I get:

No instance for (Integral (Float -> Int -> Float)) arising from a use of `fromIntegral'

I am new to Haskell.

1
(^) :: (Num a, Integral b) => a -> b -> a. Because Float is not an instance of the Integral type class, you can't use the ^ operator to raise a number to a power whose value is of type Float.jub0bs
Thanks for the answer!Jorge Devoto

1 Answers

6
votes

(**) can be used to take powers of Float exponents....

(^) is only for integral exponents.

2 ^ 2.1 --fails
2 ** 2.1 --works