
Achim Schneider
As for how to express it in code: I'd recommend a combination of a State monad to track the indentation, and the underused[1] Applicative interpretation of lists to concatenate stuff. >>= would function as concatenation of lines, getting the state, while the indent function would first set it to the new level, then execute the passed sub-action, and finally reset it to the old level. You're going to need a way to concatenate two strings without doing a line-break, too, of course.
Make that "Reader Monad" and "execute the passed sub-action with the new level inside a new monad" -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.