갈루아의 반서재

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.