我希望能够创建VB(.net)中的运算符,如下所示
Console.WriteLine ( 16 Mod 2 )
Run Code Online (Sandbox Code Playgroud)
产生如下所示的输出
0
Run Code Online (Sandbox Code Playgroud)
如您所见,这使代码更容易阅读.我将如何制作这样做的功能?
我尝试了以下格式
equal :: Integer -> Integer -> bool
x `equal` y = x == y
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
*Main> 5 equal 5
<interactive>:1:1: error:
* Non type-variable argument
in the constraint: Num ((Integer -> Integer -> Bool) -> t -> t1)
(Use FlexibleContexts to permit this)
* When checking the inferred type
it :: forall t t1.
(Num ((Integer -> Integer -> Bool) -> t -> t1), Num t) =>
t1
*Main>
Run Code Online (Sandbox Code Playgroud)
出了什么问题,我该如何正确地做到这一点?
equal当你调用它时,你需要使用反引号,就像你定义它一样.
5 `equal` 5
Run Code Online (Sandbox Code Playgroud)
你写它的方式,Haskell认为你试图equal作为一个参数传递5,而不是相反.