What good is metaprogramming, anyway?

Something that's annoying in Haskell is writing generic, structurally-inductive functions. Usually these are done by writing a helper class, and giving it instances for each of the GHC.Generics types. Doing this by hand is frustrating; there's a lot of repetition, but there's no good way to automate away the pain.

This is a good use case for tactic metaprogramming. Even though each instance is necessarily different, they are all doing the same thing spiritually --- recursing to the interesting K1 case. As you can see in the gif, I can write one tactic metaprogram, and run it at each instance. The synthesized code leaves behind a few holes, which correspond exactly with the choices I need to make as a programmer.

When I later decide that my `yo` function should have taken a boolean, I can simply undo running the metaprograms, change my types, and then rerun the metaprograms. No futzing about; just say what you mean, and let Wingman take care of the rest.

If this is the sort of code you don't want to have to write for yourself, please consider becoming a patron. Your support helps me work full-time on code automation like this!

By becoming a patron, you'll instantly unlock access to 11 exclusive posts
1
Image
9
Writings
1
Video
By becoming a patron, you'll instantly unlock access to 11 exclusive posts
1
Image
9
Writings
1
Video