
Hi Martin If you are building syntax as a sequence of commands (or statements) a common idiom is to collect them with a Writer monad. Andy Gill's Dotgen on Hackage is a nice realization of this idiom. See the how example included in the package has acceptably nice syntax without obliging the implementation to use complex facilities such as Template Haskell. In the source code, the data type GraphElement represents the main statement types in GraphViz's "dot" language. The data type Dot is the monad - here a combination of a Writer monad and a State monad, with the State monad supplying unique integers for fresh identifiers. The monad is written as a direct combination of State and Writer (it is perhaps more common to rely on _monad transformers_ but once you know what you are looking at, Andy's code is simple and clear). http://hackage.haskell.org/package/dotgen Best wishes Stephen