I usually find Design Patterns materials frivolous/unnecessary, but I really liked this one for being direct to the point!
The "idea" is the part I think can be relevant. The diagrams are OOP-dependent, but the text can be implemented in any paradigm/way, sometimes in a very simple way:
'Visitor' - just a function map
'Factory' - type inferring can be used, in most cases, as a default "built-in" factory.
The Visitor Pattern gives you a cumbersome, but type safe encoding of a closed sum type, in a language that has products (tuples/class fields) and exponents (functions) but doesn't have closed sum types.
How would a function map give you type safety around the sum type encoding?
[a] pattern is a clunky/hack to implement an inferior-and-limited version of [a more expressive construction].
Seems to be the gist of it. I remember someone talking about how most design patterns are basically structured ways to make up for the deficiencies of the language you are using.
3
u/[deleted] Dec 09 '13 edited Dec 09 '13
I usually find Design Patterns materials frivolous/unnecessary, but I really liked this one for being direct to the point!
The "idea" is the part I think can be relevant. The diagrams are OOP-dependent, but the text can be implemented in any paradigm/way, sometimes in a very simple way:
'Visitor' - just a function map
'Factory' - type inferring can be used, in most cases, as a default "built-in" factory.