More fold methods: cata
, cataM
, gcata
, gcataM
, hylo
, hyloM
, ghylo
,
ghyloM
, histo
, histoM
, ghisto
, ghistoM
, and more.
Easier to maintain; adding nodes means you just have to update your algebras and your functor instance. With the hand-written ones you’d have to update each of those methods, as well as your algebras.
If you want to mix together/extend the ADT, you can do so using a simple coproduct (like Either
)
Tail-rec for free
Scales with complexity more easily.
Much easier to read, especially before you've studied recursion schemes.
In most business situations you'll only want one, maybe two of the fold methods mentioned above. So maintenance overhead could be negligible
Writing the expressions doesn't require any embed
rigamaroll.
Performance, because less boxing.
This can all usually be done away with using the Finally Tagless
pattern.
Rewrite cata
in the hand-written interpreter to be tail-recursive. You can use the scastie link at the top of the file to mess around with it.