Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the /= operator in Haskell mean?

Tags:

haskell

I am reading Learn You a Haskell, which contains 5 /= 5. I am not so sure what this means. Does the first expression mean 5 / 5 = 5? But, then, it shouldn't be True.

like image 314
Bunny Rabbit Avatar asked Dec 22 '15 12:12

Bunny Rabbit


People also ask

What does the operator do in Haskell?

Haskell provides special syntax to support infix notation. An operator is a function that can be applied using infix syntax (Section 3.4), or partially applied using a section (Section 3.5).

What does == mean in Haskell?

The == is an operator for comparing if two things are equal. It is quite normal haskell function with type "Eq a => a -> a -> Bool". The type tells that it works on every type of a value that implements Eq typeclass, so it is kind of overloaded.

How do you write not equal to in Haskell?

'/=': This is the basic representation of the not equal operator in Haskell, also it is an inbuilt feature provided by the Haskell language, so we do not require to include any library or external dependency for this to use this in the program.

How do you check for equality in Haskell?

We can also compare two numerical values to see which one is larger. Haskell provides a number of tests including: < (less than), > (greater than), <= (less than or equal to) and >= (greater than or equal to). These tests work comparably to == (equal to).


2 Answers

It means not equal. So 5 /= 5 is false as 5 == 5 is true.

x /= y = not (x == y)

As suggested, it recalls the mathematical symbol "≠" (/=) opposite to "=" (==).

like image 109
Randomize Avatar answered Sep 22 '22 09:09

Randomize


The == operator means "is equal".

The /= operator means "is not equal".

It's supposed to be reminiscent of the mathematical "≠" symbol (i.e., an equals sign with a diagonal line through it).

like image 41
MathematicalOrchid Avatar answered Sep 19 '22 09:09

MathematicalOrchid