Functor, Foldable and Traversable for Expr

Sebastian Graf sgraf1337 at
Mon Jun 18 12:43:05 UTC 2018

Hi everyone,

I'm repeatedly wondering why there are no `Functor`, `Foldable` and
`Traversable` instances for `Expr`.

Is this just by lack of motive?
I could help there: I was looking for a function that would tell me if an
expression mentions `makeStatic`. After spending some minutes searching in
the code base, I decided to roll my own thing in `CoreUtils`.
I really couldn't think about a good name, so I settled for
`anyReferenceMatching :: (b -> Bool) -> Expr b -> Bool` and realized that I
could generalize the function to `foldMapExpr :: Monoid m => (b -> m) ->
Expr b -> m`.

Occasionally this need pops up and I really want to avoid writing my own
traversals over the syntax tree. So, would anyone object to a patch
implementing these instances?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ghc-devs mailing list