728x90
A 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
- ghci> :t (==)
- (==) :: (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! 의 내용을 학습을 위해 요약한 것입니다.
728x90
'프로그래밍 Programming' 카테고리의 다른 글
Haskell_004 Some basic typeclasses - Eq, Ord, Show, Read, Enum, Bounded, and Num (0) | 2018.03.16 |
---|---|
Haskell Type, Typeclass, and Type variables (0) | 2018.03.16 |
Haskell_ 002 Type variables (0) | 2018.03.09 |
Haskell_ 001 Type and typeclass (0) | 2018.03.05 |
하스켈 패키지 삭제하기 How to uninstall a Haskell package installed with stack? (0) | 2018.02.06 |