{-

I want to override Prelude.^ (as an academic exercise).

Can it be done? How?

Trent

-}

(^) :: Int -> Int -> Int
m ^ 0 = 1 
m ^ n = m * (m ^ (n-1))

{-
Hutton, Graham. Programming in Haskell (p. 263). Cambridge University Press. Kindle Edition. 2016.
-}

{-

Result

[1 of 1] Compiling Main             ( ex6_3b.hs, interpreted )

ex6_3b.hs:3:16: error:
    Ambiguous occurrence ‘^’
    It could refer to either ‘Prelude.^’,
                             imported from ‘Prelude’ at ex6_3b.hs:1:1
                             (and originally defined in ‘GHC.Real’)
                          or ‘Main.^’, defined at ex6_3b.hs:2:3
  |
3 | m ^ n = m * (m ^ (n-1))   |                ^
Failed, no modules loaded.
-}

-- So I try

(^) :: Int -> Int -> Int
m Main.^ 0 = 1 
m Main.^ n = m * (m Main.^ (n-1))

{-

Result

Prelude> :reload

ex6_3b.hs:2:3: error: Qualified name in binding position: Main.^
  |
2 | m Main.^ 0 = 1    |   ^^^^^^
[1 of 1] Compiling Main             ( ex6_3b.hs, interpreted )
Failed, no modules loaded.

-}