3 ms·
This reminds me of this article: "The visitor pattern is essentially the same thing as Church Encoding" [0], although I think this comment [1] and this one [2]
by trealira 2y ago
This reminds me of this article: "The visitor pattern is essentially the same thing as Church Encoding" [0], although I think this comment [1] and this one [2] on HN explain it better. The article is written in Haskell, but it's basically saying that, because object-oriented programming languages lacked sum types, the visitor pattern makes the transform from
(a | b | c) -> T
to
(a -> T, b -> T, c -> T) -> T
where (a | b | c) is a sum type saying "it can be either a of type a, type b, or type c", and (a -> T, b-> T, c -> T) is a stand-in for a record of functions (i.e. the v-table of an instance of a visitor class).
[0]: https://www.haskellforall.com/2021/01/the-visitor-pattern-is-essentially-same.html https://www.haskellforall.com/2021/01/the-visitor-pattern-is...
[1]: https://news.ycombinator.com/item?id=26034790 https://news.ycombinator.com/item?id=26034790
[2]: https://news.ycombinator.com/item?id=26024600 https://news.ycombinator.com/item?id=26024600
- trealira 2y agoLooking back but can't edit. The first line should say ((a | b | c) -> T) -> T This is just a mistake I made paraphrasing link 1.