haskell,ghc,scrap-your-boilerplate,ghc-generics

It sounds like you want a Functor instance. This can be automatically derived by GHC using the DeriveFunctor extension.

haskell,ghc,generic-programming,template-haskell,scrap-your-boilerplate

If you leave the recursion in your data type open you end up suffering an extra constructor everywhere, but can layer in annotations freely without changing most of your skeletal tree. data Hutton x -- non-recursive functor type = Int Int | Plus x x deriving Functor newtype Tie f...

haskell,functional-programming,generic-programming,scrap-your-boilerplate

Often when making transformations on complex data types, we only need to affect small pieces of the structure---in other words, we're targeting specific reducible expressions, redexes, alone. The classic example is double-negation elimination over a type of integer expressions: data Exp = Plus Exp Exp | Mult Exp Exp |...

haskell,ghc,scrap-your-boilerplate,ghc-generics

The short answer is, this isn't possible, because Functor requires that the changing type variable be in the last position. Only type constructors of kind * -> * can have Functor instances, and your Expr doesn't have that kind. Do you really need a Functor instance? If you just want...