![](/img/trans.png)
[英]How can I find out where a type, data constructor or typeclass is defined?
[英]How can I find out the type of operator “+”?
在GHCi,版本8.6.3( https://repl.it/languages/haskell )中,我想知道如何找出運算符“+”的類型。 我想看看它的類型是否為num a, b,c => a -> b -> c
或num 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.