Here's my code, trying to redefine *
. It could be achieved only when *
previously hided:
import Prelude hiding (*)
(*) :: Int -> Int -> Int
x * 0 = 0
x * y = x + x*(y-1)
But it doesn't work:
$ ghci test.hs
GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help
test.hs:1:24: error: parse error on input ‘*’
Failed, modules loaded: none.
Prelude>
I could hide other function as:
import Prelude hiding (read)
import Prelude hiding (show)
while it doesn't work for operator like *
, +
, -
.
How do I hide them?
If you want to hide the name completely, you'll need to perform the import inside each function of your module that uses NumPy: def f1(stuff): import numpy as np ... def f2(stuff): import numpy as np ... ... that leading underscore makes sense.
The syntax for importing modules in a Haskell script is import <module name>. This must be done before defining any functions, so imports are usually done at the top of the file. One script can, of course, import several modules. Just put each import statement into a separate line.
A qualified import allows using functions with the same name imported from several modules, e.g. map from the Prelude and map from Data.
Recall how you query ghci
for type of a function:
:t read
:t show
About operator:
Do you type :t +
?
No, you would receive a parse error then.
You do :t (+)
.
As for your case, you hide it with additional brackets: ((*))
import Prelude hiding ((*))
(*) :: Int -> Int -> Int
x * 0 = 0
x * y = x + x*(y-1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With