导入时如何隐藏操作员?

J.K*_*vji 7 haskell

这是我的代码,试图重新定义*.只有在*以前隐藏时才能实现:

import Prelude hiding (*)

(*) :: Int -> Int -> Int
x * 0 = 0
x * y = x + x*(y-1)
Run Code Online (Sandbox Code Playgroud)

但它不起作用:

$ ghci test.hs
Run Code Online (Sandbox Code Playgroud)

GHCi,版本8.0.1:http ://www.haskell.org/ghc/:?求助

test.hs:1:24:错误:输入'*'解析错误

失败,模块加载:无.

前奏>

我可以隐藏其他功能:

import Prelude hiding (read)

import Prelude hiding (show)
Run Code Online (Sandbox Code Playgroud)

虽然它并不适用于运营商一样工作*,+,-.

我该如何隐藏它们?

Rah*_*ahn 17

回想一下如何查询ghci函数类型:

:t read
:t show
Run Code Online (Sandbox Code Playgroud)

关于运营商:

你打字:t +吗?

不,那么你会收到一个解析错误.

你呢:t (+).

至于你的情况,你用其他括号隐藏它: ((*))

import Prelude hiding ((*))

(*) :: Int -> Int -> Int
x * 0 = 0
x * y = x + x*(y-1)
Run Code Online (Sandbox Code Playgroud)