[erlang-questions] "Design patterns" for functional languages?

Richard A. O'Keefe ok@REDACTED
Thu Aug 7 03:13:41 CEST 2008


On 6 Aug 2008, at 6:46 pm, David Mitchell wrote:
> I'm not sure I agree with the statement quoted by Michael that FP
> doesn't have the shortcomings of OO so GoF-like patterns aren't
> necessary.

It _is_ fair, however, to say that Lisp and Smalltalk don't have
the shortcomings of C++, so that many of the GoF patterns are not
needed for them (or are so very obvious that no-one ever thought
they needed names).

It might be worth reading "Why Functional Programming Matters" by
John Hughes.  You can find the link in
http://www.haskell.org/haskellwiki/Introduction
and the rest of the page is probably a good idea anyway.

Let's take one example (not in that paper).
In C++ there is a "Design Pattern" called "Resource Allocation is
Initialisation".  What it's really about is resource *release*.
The Haskell equivalent is a *function* called "bracket", not a
pattern.

I'm on the Haskell-Café mailing list.  People there are into
category theory in a big way.  Where a Lisp programmer might
write a macro, a Haskeller will probably introduce a new kind
of Monad Transformer or something.

The point is that in either case the common "pattern" will
enter your library not as diagrams in a book but as actual
reusable code you can call.

Just like "behaviours" in Erlang, come to think of it.

There are patterns at the level of "idioms", like
"tail recursion", "accumulator parameter", "handle message
priority with nested receives" and so on.  It might be no
bad thing to have a list of those.  (The Gang of Five saw
idioms as a useful pattern level.)




More information about the erlang-questions mailing list