Combinator pattern

From HaskellWiki
Revision as of 20:26, 12 March 2007 by MathematicalOrchid (talk | contribs) (Somebody who knows stuff should check this...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.


Libraries such as Parsec use the combinator pattern, where complex structures are built by defining a small set of very simple 'primitives', and a set of 'combinators' for combining them into more complicated structures. It's somewhat similar to the Composition pattern found in object-oriented programming.

In the case of the Parsec, the library provides a set of extremely simple (almost trivial) parsers, and ways to combine small parsers into bigger parsers. Many other libraries and programs use the same ideas to build other structures:

  • Parsec builds parsers out of smaller parsers.
  • The School of Expression (SOE) graphics library builds pictures out of individual shapes.
  • The SOE book also mentions a library to build music out of individual notes and rests.
  • Another textbook describes building financial contracts.
  • [Software transactional memory] builds big transactions out of smaller ones.
  • The Haskell IO system itself builds whole programs out of small I/O actions using >>= and return.