In GHCi, version 8.6.3 (https://repl.it/languages/haskell), I would like to know how to find out the type of operator "+". I want to see if its type is num a, b,c => a -> b -> c
or num a, b,c => (a,b) -> c
.
But I can't find its type out. It also affects the next expression in an unknown way. Why do I fail and what shall I do then?
:type +
:type not
<interactive>:1:1: error: parse error on input ‘+’
:type not
not :: Bool -> Bool
=> "12"
This way:
> :type (+)
(+) :: Num a => a -> a -> a
And also
> :t (+) 4
(+) 4 :: Num a => a -> a
> :t (+) 4 3
(+) 4 3 :: Num a => a
In the Haskell's console, you have to use the :t
key giving to it a value such as you would use it in your program, some examples:
plus = +
will give an error
plus = (+)
it's ok:
ghci> :t plus
ghci> :t (+)
Num a => a -> a -> b
so:
plusOne = + 1
will give you an error also
but
plusOne = (+ 1)
plusOne' = (1 +)
it's Ok:
:t plusOne'
:t plusOne
:t (1 +)
:t (+ 1)
Num a => a -> a
and finally:
twoPlusOne = 2 + 1
:t twoPlusOne
:t 2 + 1
Num a => b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With