Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you hide an operator when importing?

Tags:

haskell

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?

like image 491
J.Kujvji Avatar asked Oct 25 '16 10:10

J.Kujvji


People also ask

How do you hide imports in Python?

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.

How do I import a package into Haskell?

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.

What is a qualified import?

A qualified import allows using functions with the same name imported from several modules, e.g. map from the Prelude and map from Data.


1 Answers

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)
like image 69
Rahn Avatar answered Nov 30 '22 22:11

Rahn