Reputation: 93
I am new to haskell and I am getting an error when compiling the following code
(^) :: Int -> Int -> Int
_ ^ 0 = 1
x ^ n = x * (x ^ (n-1))
The error is this:
Ambiguous occurrence `^'
It could refer to
either `Prelude.^',
imported from `Prelude' at test.lhs:1:1
(and originally defined in `GHC.Real')
or `Main.^', defined at test.lhs:107:5
Upvotes: 1
Views: 57
Reputation: 28416
Long story short, Prelude
has that function already and you are redefining it, so the compiler doesn't know which one to pick.
If you put
import Prelude hiding ((^))
on the top of your file, you'll resolve the ambiguity in favour of your definition by hiding the other one from the Prelude
.
Upvotes: 5