Is there a functional-programming equivalent to the Gang of Four Design Patterns book? That is, is there a book that explains and gives examples of how commonly-needed code structures are implemented functionally? I think seeing that would give me a better idea of how to go about using in practice the functional concepts whose theory I understand.
The patterns movement started because object-oriented programming was often turning into "spaghetti objects" : a confusing maze of twisty little interacting objects that looked all the same. Patterns were an attempt to restrict the chaos into a set of known channels -- kind of like what Structured Programming did for procedural programming: reject arbitrary gotos and branches for a restricted set of well behaved control structures.
Functional programming doesn't have this problem. There's already a pretty small set of functional patterns that are usually built into functional languages: map, apply, reduce, recursion, etc., and are covered in any book on functional programming. Functional programming IS a restricted style of programming, so it didn't need to grow a set of restricted conventions to limit the chaos.
The GoF patterns were written for problems with OOP, and when you change paradigms then the patterns can be shown as not being an issue.
For example, with AOP I believe it was 15-18 of the 24 patterns were obsolete as the solution becomes trivial to solve.
The Little Schemer and its sequels, the Seasoned Schemer and the Reasoned Schemer, are not precise equivalents of Design Patterns, but functional programming is not the precise equivalent of OO. The patterns tend to be lower-level, at the individual function level.
So the Schemer books tend to be lower level. Also, they're tutorials, not catalogues.
- The Little Schemer covers the basics of recursion and higher-order programming.
- The Seasoned Schemer is more advanced variations on the same.
- The Reasoned Schemer covers creation of an embedded DSL (Prolog, essentially).
I've only read a little of the Little MLer, but I think it covers abstract data-types: how to program with them.
For all the other "functional design patterns" I know, I've picked up from other people, read in papers, or seen in existing code. But if I think of a more concentrated source, I'll add it here.
- Monads are an important design pattern, probably the only thing in functional programming I would not feel funny calling 'design pattern'. It's very general, so reading the implementations of this pattern is equivalent to reading a whole family of OO design patterns. All About Monads' Catalog of Standard Monads is the best list I know of.
Edward Yang recently wrote a blog article describing the general relationship between the Gang of Four patterns and the patterns typically used by Haskell programmers.
http://blog.ezyang.com/2010/05/design-patterns-in-haskel/
You might try starting there.
However, as of this point I am unaware of any book on functional design patterns. In general this seems to be a difference in culture. In the programming languages community, the need for a design pattern is often seen as the equivalent of a 'bad code smell' in its own right and is something to be encapsulated behind a higher order function, a macro-based facade, or even a new language feature, rather than enshrined and stylized.
In some sense, we just have one pattern: replacing other patterns with an appropriate EDSL or combinator set.