Nice! See also http://ro-che.info/articles/2013-03-11-generalizing-gfoldl.html http://ro-che.info/articles/2013-03-29-gtraverse-vs-gfoldl.html http://hackage.haskell.org/package/traverse-with-class * John Meacham <john@repetae.net> [2014-05-12 17:36:43-0700]
Before
http://repetae.net/drop/TypeSyns_old.hs
and after
http://repetae.net/drop/TypeSyns_new.hs
that's right, the work of a 550 line complicated file done in a few lines.
The magic is in FrontEnd.Syn.Traverse where I have a class that recurses over arbitrary source syntax and takes a
data HsOps m = HsOps { opHsDecl :: HsDecl -> m HsDecl, opHsExp :: HsExp -> m HsExp, opHsPat :: HsPat -> m HsPat, opHsType :: HsType -> m HsType, opHsStmt :: HsStmt -> m HsStmt }
as an argument, by recursively defining your ops by 'tying the knot' each of the routines will recurse down the others. quite handy. Now I have about 2500 lines of code to excise from FrontEnd/.
Many improvements to the front end have been put off due to the sheer amount of traversal code that has to modified for every new syntax construct. good times.
John
-- John Meacham - http://notanumber.net/ _______________________________________________ jhc mailing list jhc@haskell.org http://www.haskell.org/mailman/listinfo/jhc