Seems to me that the entire interesting bit is "provided" by `a` being a monoid. (I agree that monoids are really interesting)
I called it `ev` because it's an evaluator/interpreter. To be able to write such a `m a -> a` function, `a` needs to have the same kind of structure that `m` is somehow representing, and you need to be able to map the operation that `m` "contains" to corresponding operations for `a`.
This is that business about free monads being useful for organizing how you write interpreters I believe.
Yep, which is why I'm saying all the interesting bits come from `a` being the monoid in that example.
In the free monad interpreter example, I have no idea though.
> all the interesting bits come from `a` being the monoid in that example.
Yeah, there's nothing deep there. I just said what I said to underscore that the converse is true, that if anyone were to hand you such a `list a -> a` function then it's encoding some monoid structure on `a` (one of often very many).
You've got the direction backwards: the point is to characterize all `m`-algebras, not to construct particular ones.
This is closely related to the usual duality between types and values. It's very common for people new to TypeScript, for instance, to think that `{a: string} | {b: number}` should be `{a: string, b: number}`, because they're thinking primarily in terms of records as sets of fields, not types as sets of values. But making the type bigger makes the set of things you can say about its values (i.e. the space of functions out of it) smaller. Algebras are similarly the "value-like" counterparts to "space-like" monads.
For example, integers with the sum function form an algebra over the list monad, because
1) for any list of ints, the sum is an int
2) the sum of [n] is just n
3) summing recursively is the same as summing over the flattened list.
More generally, the algebras over the List monad are exactly the monoids, with ‘merge [a, b]‘ as the monoid operation. Algebras over the Maybe monad are pointed sets, with ‘merge Nothing‘ as the distinguished point. A lot of algebraic structures (Lawvere theories) can be defined by a monad this way.
[0] Laws that ‘merge‘ should satisfy: merge (return x) == x fmap merge (merge mx) == merge (join mx)