PLDI

2 thoughts
last posted Dec. 7, 2013, 4:40 a.m.

1 earlier thought

0

Church Encoding is like the Visitor Pattern

Church Encoding is like the visitor pattern, especially for booleans, lists, and so on.

Boolean is the most obvious - a Church Boolean is a function that takes two functions, one to call if the boolean is true and one to call if the boolean is false. The visitor pattern version would be for boolean to accept a visitor with two methods.

For lists there are a few alternate variations in lambda calculus, but it's not hard to imagine a visitor pattern implementation that calls back to an empty nullary visitor or a nonEmpty binary visitor method.