갈루아의 반서재

typeclass is a sort of interface that defines some behavior.

If a type is a part of a typeclass, that means that it supports and implements the behavior the typeclass describes.


Type signature of the == function
  1. ghci> :t (==)  
  2. (==) :: (Eq a) => a -> a -> Bool  
The equality operator, == is a function. +*-/ and pretty much are all operators. 
If a function is comprised only of special characters, it's considered an infix function by default. If we want to examine its type, pass it to another function or call it as a prefix function, we have to surround it in parentheses.

class constraint. : Everything before the => symbol

The equality function takes any two values that are of the same type and returns a Bool.  The type of those two values must be a member of the Eq class (this was the class constraint).
The Eq typeclass provides an interface for testing for equality
All standard Haskell types except for IO and functions are a part of the Eq typeclass.


Type signature of the elem  function
The elem function has a type of (Eq a) => a -> [a] -> Bool because it uses == over a list to check whether some value re looking for is in it



본 카테고리의 내용은 Learn You a Haskell for Great Good! 의 내용을 학습을 위해 요약한 것입니다.