Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the type of the unary operator '-' in haskell

Tags:

haskell

In haskell, negative numbers come from using the unary operator '-' in front of a number, but the subtraction function also use '-'. So when you type :t (-) in ghci, you only get the result of the subtraction function's type like

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

But is it possible to get the type of the "negate operator" in ghci? I know this is trivial, but I am curious.

like image 414
richard.g Avatar asked Mar 16 '14 14:03

richard.g


People also ask

Is unary operator in C * &?

The unary address-of operator (&) takes the address of its operand. The operand of the address-of operator can be either a function designator or an l-value that designates an object that is not a bit field and is not declared with the register storage-class specifier.

Which is the unary operator *?

A unary operator, in C#, is an operator that takes a single operand in an expression or a statement. The unary operators in C# are +, -,!, ~, ++, -- and the cast operator.

What are the two types of unary operators?

The Unary decrement operator is of two types: the Pre decrement operator and the Post Decrement operator.

How many unary operators are there in Haskell?

In Haskell there is only one unary operator, namely the unary minus. It has been discussed in length, whether the unary minus shall be part of numeric literals or whether it shall be an independent operator.

What are unary operators in Java?

Java unary operators are the types that need only one operand to perform any operation like increment, decrement, negation, etc. It consists of various arithmetic, logical and other operators that operate on a single operand.

How do you write unary minus in Haskell?

It can be written in prefix notation like in or in postfix notation ( factorial ). In Haskell there is only one unary operator, namely the unary minus . It has been discussed in length, whether the unary minus shall be part of numeric literals or whether it shall be an independent operator.

How do you use the unary plus operator?

The unary plus operator is represented as the "+" symbol, and it does not change to the operand value. It is the unary increment operator, which is denoted by the "++" symbol. The "++" symbol represents the operand's value is increased by 1. It can be used in two ways, as the post-increment and the pre-increment.


1 Answers

You could eta expand it:

Prelude> :t \x -> -x
\x -> -x :: Num a => a -> a
like image 96
J. Abrahamson Avatar answered Oct 06 '22 15:10

J. Abrahamson