The visitor pattern is essentially the same thing as Church encoding
Like a lot of functional programming writing, this piece seems impenetrable because it comes at a problem from a peculiar angle: given that I have this hammer, what nails can I hit?<p>Starting from the recognition that there’s a trick you can do with typed lambdas to represent ‘types’, it then proceeds to show that you can use pattern matching on those ‘types’ to implement something like the visitor pattern.<p>It never even comes close to showing what that wins you. We found a gang-of-four shaped nail. Done.<p>But the thing is the visitor pattern is a response to a particular <i>problem</i>: double dispatch.  You have some logic that needs to vary based on two different types. The classic example is a game where you want to calculate damage effects for different kinds of attack against different kinds of monsters.<p>If you start from a problem like that, the visitor pattern turns out to be useful (but is not the only way to solve it).<p>It’s possible - hard to tell from first reading - that what this article is actually suggesting is that Church Encoding can be used to solve double dispatch problems, by letting you encode a visitor pattern in a particularly elegant way.<p>Which would be a much more interesting insight!<p>It’s far more likely that you are facing a double dispatch problem and looking for a programming tool to solve it with, than that you have elected to use Church encoding to build some types for some reason and are now looking to determine which gang-of-four patterns you can implement in your new type calculus...