Haskell: Functors, Applicatives and Monads
Relationship:
|Functors |
|__________________ |
|Applicatives | |
|_______________ | |
|Monnads | | |
|| | |
|| |
|________________|
Functors:
Definition:
A class instance withfmap
implemented.
It should satisify the law:fmap id = id
: there exits an identity function s.t. the function does not change anyhting about the container.
The law make sure that fmap does not change the structure of the container and it impliesfmap (g . h) = (fmap g) . (fmap h)
(distrubitivity?)Intuition:
Container(type function) of (not concrete, i.e. the type should be a type function that accepts another type as parameter)types wherefmap
can be used (a function that a takes in a functionf :: (a -> b)
wherea
andb
are non concrete types and output a functionf' :: (functorInstance a -> functorInstance b)
. i.e. apply the functionf
to every element in the coontainer).Syntax:
1
2
3instance Functor $TYPE_FUNCTION where
fmap :: (a->b) -> $TYPE_FUNCTION a ->$TYPE_FUNCTAION b
$FMAP_DEFINITION_HERE