I am rewriting the gcd
function for an assignment, but when I'm trying to hide gcd
, like so:
import Prelude hiding ((gcd))
I get the error
Parse error on input'gcd'.
I'm certain I've completed the redefinition of gcd
, but I can't stop the error
Ambiguous occurrence, it could refer to 'Prelude.gcd'
unless I manage to hide gcd
.
Here is my full code (apologies can't find upload file):
import Prelude hiding ((||))
import Prelude hiding ((gcd))
gcd :: Int -> Int -> Int
gcd x y
| x == y = x
| x < y = gcd x (y-x)
| otherwise = gcd (x-y) y
And here is my error after changing to import Prelude hiding (gcd)
:
If you want to hide multiple things from a module, you need to import it once and specify everything to hide. Importing it twice will result in each line's exclusions nullifying the other. So do this instead:
import Prelude hiding ((||), gcd)
(And as previously mentioned in the comments, gcd
isn't an operator, so it shouldn't have parentheses around it like ||
does.)