3 ms·
Maybe a good example that ties both together is some sort of filter on a list? If you add more constraints (more processing) the list gets smaller. Suppose I h
by foxes 6y ago
Maybe a good example that ties both together is some sort of filter on a list? If you add more constraints (more processing) the list gets smaller.
Suppose I have a function f : x -> y. x -> y is also a functor in y. If you have an x-> y but want x->z, you can use y->z and adjust your original function by post processing the output of f. However suppose you want w -> y but you still only have f. You need to post process with w->x. So f is covariant in y, contravariant in x. Things change in the opposite direction of the adaptor.
Perhaps serialisation is a useful example?
Perhaps contravariance becomes even more useful if you use it in some profunctor dimap where you have a producer and consumer and process, eg moving through a data structure and pre/post processing things.
https://www.youtube.com/watch?v=OJtGECfksds https://www.youtube.com/watch?v=OJtGECfksds
- magicalhippo 6y ago> You need to post process with w->x Did you mean pre-process?