Start with the following generalization
data Q a b
= L a
| R b
| B a bFor which Q `Fizz `Buzz records the original data type from
>>3(note, I'm using ` to lift an ADT from the value to type level, this is a new GHC extensions called data primes which makes haskell closer to a research language)
Now following the work of Hutton and Wouter let's invert this statagorically to emephor it into using category theoretic idioms:
Q "=" Mu (KEEP :& DROP :+ DROP :& KEEP :+ KEEP :& KEEP)There are a few things happening here that deserve some explanation. First of all Mu is the recursive endotensor which GHC pushes deeper into the functor.
+ and & are the usual sums and products which we know are bifunctors. This gives us a true functorial description of fizzbuzz once and for all. Furthermore, it's possible to do this generalically for any number of "buzzes" in a dependently typed language.
Once agains we've seen that haskell is the nothing of thing-in-itself which enables truly abstract mathematical thought and programing to blend beautifully!