[Haskell-cafe] Generic Traversal of ASTs

Richard Yu richardyu042 at gmail.com
Mon May 24 20:51:17 UTC 2021


I have a question about generic traversal/transformation of nested data
structures. From what I understand the main options available are SYB,
Uniplate, GHC.Generics and Data.Lens (although I am under the impression
this requires record types). The data structure I am attempting to traverse
is similar to this simplified version:

data SExpr = Expr | Const
data Const = B bool | I int
data Expr  = Lambda String SExpr | If Expr ...

I have attempted to use Uniplate and GHC.Generics to traverse the built AST
and modify for example, the string of a Lambda type, but have not been able
to figure out how to get any of the libraries to typecheck. The examples or
docs I found were not quite enough. Does anyone know of examples that might
help or explain how I should be using the generic libraries?
In addition if I moved to writing the AST with GADTs, do some generic
traversal strategies/libraries stop working?


Many thanks,
Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210524/9030a608/attachment.html>


More information about the Haskell-Cafe mailing list