[Haskell-beginners] How to construct complex string

Stephen Tetley stephen.tetley at gmail.com
Tue Aug 6 19:01:45 CEST 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130806/f5d3e94f/attachment.htm>


More information about the Beginners mailing list