繁体   English   中英

如何找出运算符“+”的类型?

[英]How can I find out the type of operator “+”?

在GHCi,版本8.6.3( https://repl.it/languages/haskell )中,我想知道如何找出运算符“+”的类型。 我想看看它的类型是否为num a, b,c => a -> b -> cnum a, b,c => (a,b) -> c

但我找不到它的类型。 它还以未知的方式影响下一个表达式。 为什么我失败了,我该怎么办呢?

   :type +
   :type not
<interactive>:1:1: error: parse error on input ‘+’
   :type not
not :: Bool -> Bool
=> "12"

这条路:

> :type (+)
(+) :: Num a => a -> a -> a

并且

> :t (+) 4
(+) 4 :: Num a => a -> a

> :t (+) 4 3
(+) 4 3 :: Num a => a

在Haskell的控制台中,你必须使用:t键给它一个值,比如你在程序中使用它,一些例子:

plus = +

会出错

plus = (+)

没关系:

ghci> :t plus
ghci> :t (+)

Num a => a -> a -> b

所以:

plusOne = + 1

也会给你一个错误

plusOne  = (+ 1)
plusOne' = (1 +)

没关系:

:t plusOne'
:t plusOne
:t (1 +)
:t (+ 1)

Num a => a -> a

最后:

twoPlusOne = 2 + 1

:t twoPlusOne
:t 2 + 1

Num a => b

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM