Re:How to make your code imply responsibilities
by ufo on Monday October 21, 2013 @12:29PM
(#6586566)
This is a neat trick that pops up from time to time. Instead of representing an algebraic data type as a bunch of cases that you can test with if-statements at runtime, you represent it as a pattern-matching function that receives a code block to run for each possibility.
https://en.wikipedia.org/wiki/Smalltalk#Control_structures
http://c2.com/cgi/wiki?VisitorPattern
https://en.wikipedia.org/wiki/Mogensen%E2%80%93Scott_encodin...
One neat example of this correspondence is continuation-passing style. For example, in Javascript: