Even more Beautiful Code (C → Haskell)
In the book Beautiful Code some code is more beautiful than other code. But there is little doubt that the opening chapter presents a regular expression matcher in a beautifully succinct fashion. As the author Brian Kernighan states: “I don’t know of another piece of code that does so much in so few lines while providing such a rich source of insight and further ideas.”
The example is written in C. I wondered if a more beautiful version could be created using a newer programming language. But we can maintatin the advantages of C and work at a slightly higher level by using lists. Since this code also uses recursion and pattern matching, Haskell is a very natural replacement.
Written on Mon Feb 4 20:00:22 2008.
Tagged as C, haskell, regex.