
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

Hi Richard - one thread of the history of work is in the “strategic programming” work of Stratego (untyped) and Strafunski (implemented in Haskell) by Eelco Visser and Ralf Lämmel (resp.).
https://strategoxt.org/Stratego/StrategoLanguage.html
https://link.springer.com/chapter/10.1007/978-3-540-25935-0_13
https://www.researchgate.net/publication/220802944_A_Strafunski_Application_...
We explicitly used this approach in our first implementation of Wrangler (with Strafunski), and continue in other work to take this approach. For example “stop_top_down” is used heavily.
HTH
Simon
On 24 May 2021, at 21:51, Richard Yu

Have you tried Multiplate?
If Multiplate is not powerful enough and you're willing to make your types
more complex, have a look at deep-transformations.
On Mon, May 24, 2021 at 4:52 PM Richard Yu
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
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Multiplate actually looks very likely for my use case - I figured there
must be some prior work in this area that I had not found yet, so thanks!
As sort of a follow up, is there a quick way to try out all of these
libraries without having to setup a new stack project every time? I used to
use the arch packages to manually invoke ghc on small files, but that only
works if the package is on the aur so I was wondering if anyone had any
thoughts.
Thanks,
Richard
On Tue, Jun 1, 2021 at 1:17 PM Mario Blazevic
Have you tried Multiplate?
If Multiplate is not powerful enough and you're willing to make your types more complex, have a look at deep-transformations.
On Mon, May 24, 2021 at 4:52 PM Richard Yu
wrote: 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
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- Richard Yu B.S Aerospace Engineering | B.S Computer Science Gemstone Honors Program University of Maryland, College Park https://github.com/beForged

As sort of a follow up, is there a quick way to try out all of these libraries without having to setup a new stack project every time?
You can use "stack install" and "stack ghc" outside of any stack project (no "stack.yaml" in any preceding directory). It will read "~/.stack/global-config/stack.yaml", that's where you can set the resolver and add "extra-deps" for packages not on stackage. Li-yao On 6/2/2021 1:02 AM, Richard Yu wrote:
Multiplate actually looks very likely for my use case - I figured there must be some prior work in this area that I had not found yet, so thanks! As sort of a follow up, is there a quick way to try out all of these libraries without having to setup a new stack project every time? I used to use the arch packages to manually invoke ghc on small files, but that only works if the package is on the aur so I was wondering if anyone had any thoughts.
Thanks, Richard
On Tue, Jun 1, 2021 at 1:17 PM Mario Blazevic
mailto:mblazevic@stilo.com> wrote: Have you tried Multiplate?
If Multiplate is not powerful enough and you're willing to make your types more complex, have a look at deep-transformations.
On Mon, May 24, 2021 at 4:52 PM Richard Yu
mailto:richardyu042@gmail.com> wrote: 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
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- Richard Yu B.S Aerospace Engineering | B.S Computer Science Gemstone Honors Program University of Maryland, College Park https://github.com/beForged https://github.com/beForged
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (4)
-
Li-yao Xia
-
Mario Blazevic
-
Richard Yu
-
Simon Thompson