The difference between == and = in Haskell

It’s still hard for me to figure out the difference between ==and =in Haskell. I know that the former has something to do with being overloaded with the type, and the latter "gives the result" to the function, but I just can't see it! Any help would be greatly appreciated.

+5
source share
5 answers

=is a special reserved character in Haskell meaning "defined as". It is used to introduce definitions. That is, you use it to create new values ​​and functions that can be referenced in the definitions of other values ​​and functions.

== , Eq a => a -> a -> Bool. (Eq), . == . , "", , () , , , "" .

:

data Foo = Foo Int

instance Eq Foo where
  (Foo x) == (Foo y) = x == y

, = == Foo!

, = , == .

+15

= . , , . . /.

== - , , typeclass Eq bool

Prelude> let a = 1
Prelude> a
1
Prelude> 5 == 5
True
Prelude> 5 == 6
False
Prelude> :t (==)
(==) :: (Eq a) => a -> a -> Bool
+2

==

:

=

:

+1

Haskell, == - , true false, = - , Haskell .

ghci> 5 == 5
true
ghci> "foo" == "bar"
false
ghci> let foo = "bar"
+1

== - , . haskell "Eq a = > a β†’ a β†’ Bool". , , Eq typeclass, .

On the other hand, = = the assignment operator, which is used to introduce definitions.

+1
source

All Articles