Type
A kind of label that every expression has. Category of things that expression fits.
:t examine the types of some expressions
:: is read as "has type of"
The parameters are separated with ->
There's no special distinction between the parameters and the return type.
The return type is the last item in the declaration.
Type Variable
1 2 | Prelude> :t head head :: [a] -> a | cs |
What is this a? It's actually a type variable. That means that a can be of any type.
Typeclass
A sort of interface that defines some behavior.
Ex) Eq typeclass provides an interface for testing for equality
If a type is a part of a typeclass, that means that it supports and implements the behavior the typeclass describes.
1 2 | Prelude> :t (==) (==) :: Eq a => a -> a -> Bool | cs |
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). All standard Haskell types except for IO and functions are a part of the Eq typeclass.
'프로그래밍 Programming' 카테고리의 다른 글
Haskell_005 Pattern matching (0) | 2018.03.17 |
---|---|
Haskell_004 Some basic typeclasses - Eq, Ord, Show, Read, Enum, Bounded, and Num (0) | 2018.03.16 |
Haskell_ 003 Typeclass (0) | 2018.03.15 |
Haskell_ 002 Type variables (0) | 2018.03.09 |
Haskell_ 001 Type and typeclass (0) | 2018.03.05 |