How many times have you heard “monads do not compose”? I’ve spent a lot of time trying to contradict this statement. But just like in math, if you want to understand something sometimes you have to change your point of view.
In this article I’m going to show you what are adjoint functors about through real programming examples. We will build a lot of useful stuff just with two simplest constructions: an arrow and a comma.
Once upon a time a farmer went to a market and purchased a wolf, a goat , and a cabbage. On his way home, the farmer came to the bank of a river and rented a boat. But crossing the river by boat, the farmer could carry only himself and a single one of his purchases: the wolf, the goat, or the cabbage. If left unattended together, the wolf would eat the goat, or the goat would eat the cabbage. The farmer’s challenge was to carry himself and his purchases to the far bank of the river, leaving each purchase intact. How did he do it?
There is an interesting problem called Trapping Rain Water. There are also a lot of truly brilliant solutions of this problem in Chris Done blogpost. But I’d like to find my own solution that would be composable, readable and involve effects.
It’s recommended to read the first part: Trying to compose non-composable: joint schemes, but if you’re not interested in details of implementation - it’s okay, in this article I’ll quickly go through the capabilities of my joint library.
Despite the fact that there are several well-typed “path” libraries in Haskell, I decided to write a new one I would like to use: the library called monopati, whose definitions are used in this post.
I lost count of how many times I’ve seen types/functions/families and another first-class abstractions that shouldn’t exist if we want to use more universal constructions. A little bit of theory can reduce and beautify our production code, and now I will try to demonstrate that.
Recently I’ve been working on distributed systems and I often need to deal with the data that may be located anywhere. We’ll see how just one algebraic construction helped to describe a problem with recycling data in general and then to solve it.