Church encoding (aka Visitor Pattern) is a way of representing data as functions: instead of
data T = C1 F1 F2 | C2 F3 F4
you can define
data T = T (forall r. (F1 -> F2 -> r) -> (F3 -> F4 -> r) -> r)
. Although the ability to represent anything as a function is nice, I've always thought the first version was preferable because it's cleaner and it does not require language extensions (explicit forall
). However, you can sometimes find church-encoded data in public libraries. What are the advantages of using that?
The examples of church encoding in public libraries:
- Iteratee
- Revision control monad
- (please help me extend the list)