The other day, chromatic blogged about his experience writing a Haskell version of the regular expression matcher that Brian Kernighan described in Beautiful Code:
It would be neat to see a Haskell version that attempted to hide the recursion. I wonder what that would look like?I’ve been reading Beautiful Code, picking out chapters here and there as I have time. While reading Brian Kernighan’s explanation of Rob Pike’s regular expression program from The Practice of Programming, I had an idle thought. “Hey, that’s a highly recursive program with complex behavior suitable for didactic purposes.”
Of course, Kernighan says that almost verbatim in the text. He also says “It’s a nicer example than Yet Another Fibonacci Sequence Generator.”
So I ported it to Haskell. I don’t promise it’s necessarily great Haskell, and I wouldn’t consider it entirely beautiful, but it appears to function.

Comments (2)
Erm. What do you mean, "hide the recursion"?
It's always possible to inline everything, but what's the point?
Posted by ADEpt | August 26, 2007 11:40 AM
ADEpt:
I was talking about hiding recursion in the way that map hides recursion. You see the abstraction and don't have to know that there's recursion under the hood.
Posted by Michael Feathers | August 28, 2007 6:59 PM