2 ms·
I have undergrad-level understanding of both abstract algebra and functional programming, and I have absolutely no idea how either your or the GP's example are
by Sharlin 6y ago
I have undergrad-level understanding of both abstract algebra and functional programming, and I have absolutely no idea how either your or the GP's example are connected to contravariant functors as understood through the lens of functional programming.
- foxes 6y agoMaybe 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?