Last active
March 11, 2019 16:52
-
-
Save mbbx6spp/c67f459bddff36686aa5a7d60bee1622 to your computer and use it in GitHub Desktop.
Intuitions on functors.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fmap :: Functor f => (a -> b) -> f a -> f b | |
| contramap :: Contravariant f => (a <- b) -> f a -> f b | |
| invmap :: Invariant f => (a <-> b) -> f a <-> f b -- NOT VALID syntax but to give an intuition. | |
| bimap :: Bifunctor p => (a -> b) | |
| -> (c -> d) | |
| -> p a c | |
| -> p b d | |
| dimap :: Profunctor p => (a -> b) | |
| -> (c -> d) | |
| -> p b c | |
| -> p a d | |
| -- putting bimap and dimap together in a slightly different way: | |
| bimap :: Bifunctor p => (a -> b) -> (c -> d) -> p a c -> p b d | |
| dimap :: Profunctor p => (a <- b) -> (c -> d) -> p b c -> p a d | |
| -- another way showing the shapes of the types | |
| bimap :: Bifunctor (p :: * -> *) => (a -> b) -> (c -> d) -> p a c -> p b d | |
| dimap :: Profunctor (p :: * -> *) => (a <- b) -> (c -> d) -> p b c -> p a d | |
| -- Note Bifunctor is covariant in both type arguments | |
| -- Note Profunctor is contravariant in the first type argument and covariant in the second | |
| -- Profunctors are often used for defining decoding and encoding pairs (e.g. JSON (de-)serialization, reading and writing to database). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment