Functional design patterns

I'm sorry I don't know of articles or books which cover in detail the different usages for all of those constructs, but I can give you a few links to individual resources.

A quite common pattern is to build monad transformers instead of simple monads (see also the link in the next paragraph). It basically means you build something that must be combined with other monads, resulting in a more complex one able to handle features of both of them.

In Real World Haskell there are a few chapters about monads. In Chapter 14. Monads the authors explain the basics and some common usages (maybe, list, state). Chapter 15. Programming with monads provides more explanations about how to effectively use them (it covers the reader monad as well). The following chapter explains how to use Parsec, but it may be more interesting to search for articles covering how it actually works: it should be a really good example of a well-organized use of monads for parsing. Fianlly, Chapter 18. Monad transformers introduces how monad transformers work and then shows how to build one, step by step. The considerations towards the final sections of the chapter are also interesting.

I read once a really interesting question on SO about creative uses of monads. The proposed links were awesome reads about the topic. With that spirit, I tried to ask the same for arrows: I definitely got less answers than the one on monads, but interesting ones nevertheless.


With respect to OOP patterns by the gang of four, there is a nice set of 3 articles by IBM about the topic in their series Functional thinking. The target functional language is Scala. They proceed by explaining usual design patterns in OOP and showing how they map into Scala.

  1. Functional thinking: Functional design patterns, Part 1. Here they cover factories, template methods, strategy, flyweight. The bottom line is that by having functions as first class values, everything is much simpler.
  2. Functional thinking: Functional design patterns, Part 2. This is about java and groovy. It adresses the adapter pattern.
  3. Functional thinking: Functional design patterns, Part 3. Here they talk about the interpreter pattern. Again, the target language is groovy.

The most relevant article w.r.t. your question is for sure the first one, but the other two may be interesting related readings nevertheless.


Lot of FP stuff are published on Oleg's site: http://okmij.org/ftp/

Presentation about FP patterns from Josh Suereth: http://jsuereth.com/intro-to-fp/


Jeremy Gibbons has a Patterns in FP blog which is destined eventually to become pretty much the book you're asking for. Of course, that's not yet in a condition to be as useful as you might want just now, but he deserves some encouragement!

Meanwhile, I'll say +1 for Brent Yorgey's Typeclassopedia. It's really useful, and if there are later parts which confuse, this site is a good place to get to the bottom of them. I know Brent keeps it under review. If he's not reaching his readers, give him some help.


My suggestion is, if you want to learn Scala, to read the book from Paul Chiusano and Runar Bjarnason:

http://manning.com/bjarnason/

Part II: Functional design and combinator libraries

  1. Making little languages
  2. JSON serialization
  3. Specification-based testing
  4. Parsers
  5. Purely functional parallelism
  6. Purely functional state

Part III: Functional design patterns

  1. The case for abstraction
  2. Monoids
  3. Functors
  4. Monads
  5. Applicative functors
  6. Traversable and foldable data structures
  7. Comonads

Part IV: Breaking the rules: effects and I/O

  1. Effects vs. side-effects
  2. Stream processing and incremental I/O
  3. Enforcing effect-scoping with the type system