[jhc] The Wonders of generic applicative traversal routines

John Meacham john at repetae.net
Tue May 13 00:36:43 UTC 2014


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/


More information about the jhc mailing list