I still have trouble getting my head around the difference between the == and = in Haskell. I know the former has something to do with being an overloaded type and the latter ‘gives the result’ of the function but I just can’t seem to get my head around it! Any help would be much appreciated.
I still have trouble getting my head around the difference between the == and
Share
=is a special reserved symbol in Haskell meaning “is defined as”. It is used to introduce definitions. That is, you use it to create new values and functions which may be referenced in the definitions of other values and functions.==is not a reserved symbol but just a run-of-the-mill function of typeEq a => a -> a -> Bool. It happens to be declared in a type class (Eq), but there’s nothing extraordinary about it. You could hide the built-in declaration of==and redefine it to whatever you wanted. But normally it means “is equal to”, and because it is part of a type class, you can define (overload) it to mean whatever you want “equality” to mean for your particular type.For example:
Note that I used
=to define==forFoo!A pithy way to think of the difference is that
=asserts equality at compile time, whereas==checks for equality at runtime.