Haskell: Functors, Applicatives and Monads
Relationship:
|Functors |
|__________________ |
|Applicatives | |
|_______________ | |
|Monnads | | |
|| | |
|| |
|________________|
Functors:
Definition:
A class instance withfmapimplemented.
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 wherefmapcan be used (a function that a takes in a functionf :: (a -> b)whereaandbare non concrete types and output a functionf' :: (functorInstance a -> functorInstance b). i.e. apply the functionfto 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
Haskell: Functors, Applicatives and Monads
https://chiatzenw.github.io/2022/06/21/Haskell-Functors-Applicatives-and-Monads/