Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out the type of operator "+"?

Tags:

haskell

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"
like image 807
Tim Avatar asked Dec 31 '22 19:12

Tim


2 Answers

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
like image 183
Will Ness Avatar answered Jan 08 '23 01:01

Will Ness


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
like image 27
A Monad is a Monoid Avatar answered Jan 08 '23 00:01

A Monad is a Monoid