[Haskell-cafe] Haskell source AST zipper with state

Andrew Seniuk rasfar at gmail.com
Thu May 3 02:52:33 CEST 2012

On Wed, May 2, 2012 at 7:20 PM, Tony Morris <tonymorris at gmail.com> wrote:
> Is there a library to traverse a source AST keeping state?

Hi Tony, I was able to do this [1] using haskell-src-exts and a state
monad.  AST traversal is possible due to HSE deriving instances for
Data in all its datatype declarations, but the traversals were of a
generic variety, rather than zippers.  I read Scrap Your Zippers [2]
and looked at various other generic zipper libs, but in the end I
managed without zippers.  Note that most zipper libs require instance
declarations for all the syntax datatypes -- Scrap Your Zippers only
requires the Data instances that HSE comes with, not sure why I was
unable to use it, probably just inexperience.

Note that the "Annotated" version of the HSE parser/AST will probably
not provide enough
 generality for the sorts of attributes you want to store (it's for
source locations, unless something changed in the most recent

Best of luck, and I'll be interested to hear other responses!


[1] http://hackage.haskell.org/freesect (in particular FreeSect*.hs)
[2] https://www.cs.indiana.edu/~adamsmd/papers/scrap_your_zippers/

More information about the Haskell-Cafe mailing list