Re:The visitor pattern is essentially the same thing as Chur...
by Gabriel439 on Thursday February 04, 2021 @08:12PM
(#26031873)
The point of the post wasn't to explain that Church encoding is a replacement for the visitor pattern. The purpose of the post was to explain that the visitor pattern is essentially the same thing as Church encoding (thus the title of the post), because I noticed a lot of people were not appreciating that connection between the two.
Re:The visitor pattern is essentially the same thing as Chur...
by skybrian on Thursday February 04, 2021 @08:59PM
(#26032187)
That's fine, but it seems like some of the confusion comes from unclear expectations? There is a vague promise at the beginning of the post that this will somehow be useful for programming:
"This post also explains how you can usefully employ the visitor pattern / Church encoding / Böhm-Berarducci encoding to expand your programming toolbox."
Re:The visitor pattern is essentially the same thing as Chur...
by Ericson2314 on Thursday February 04, 2021 @07:32PM
(#26031570)
Church encoding is not a good way to write real-world programs. There, I said it.
I said it was useful theory. E.g. a way to shrink a programming language to remove data types so there's less drudgery in proofs about that language. That's not a regular programming task in the slightest.
It's apparently not useful in languages with sum types, and it doesn't seem useful in an object-oriented language either (where you'd use the normal visitor pattern). So, when is it useful? The author doesn't have a practical example.
I guess there might be a language somewhere that has neither sum types nor methods? It's kind of a reach.
But, maybe it's useful educationally, as a good way to think about problems? That doesn't seem particularly likely either, considering that you can apply the visitor pattern just fine without knowing about Church encodings at all.
Disparaging "double dispatch" as "epicycles" while promoting Church encoding as "legit" just seems out of touch with how practical programmers think. I can't think of any reason why I'd want to use Church encoding to explain what's going on to a newbie.
Maybe there is some other situation where it's useful, but it's not explained.