
What the original author appears to want is "string rewriting". Dave Bayer had a nice implementation in this thread... http://www.haskell.org/pipermail/beginners/2010-February/003399.html His question was actually about something else, but the continuation of the thread illuminates his technique, see my reply and the messages following it up: http://www.haskell.org/pipermail/beginners/2010-February/003433.html String rewriting is not particularly straight-forward in Haskell because you are consuming the input string and generating output at "different speeds" so using direct recursion and pattern matching makes for monolithic code. By "different speeds" I mean you might want to look at one or several characters in the input to match a token, and produce zero, one or many characters as output at each rewrite step.