Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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...

[1]: https://news.ycombinator.com/item?id=26034790

[2]: https://news.ycombinator.com/item?id=26024600



Looking 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: