Comonoids are mentioned, for example, in Haskell's distributive
library docs:
Due to the lack of non-trivial comonoids in Haskell, we can restrict ourselves to requiring a Functor rather than some Coapplicative class.
After a little searching I found a StackOverflow answer that explains this a bit more with the laws that comonoids would have to satisfy. So I think I understand why there's only one possible instance for a hypothetical Comonoid typeclass in Haskell.
Thus, to find a nontrivial comonoid, I suppose we'd have to look in some other category. Surely, if category theorists have a name for comonoids, then there are some interesting ones. The other answers on that page seem to hint at an example involving Supply
, but I couldn't figure one out that still satisfies the laws.
I also turned to Wikipedia: there's a page for monoids that doesn't reference category theory, which seems to me as an adequate description of Haskell's Monoid
typeclass, but "comonoid" redirects to a category-theoretic description of monoids and comonoids together that I can't understand, and there still don't seem to be any interesting examples.
So my questions are:
- Can comonoids be explained in non-category-theoretic terms like monoids?
- What is a simple example of an interesting comonoid, even if it's not a Haskell type? (Could one be found in a Kleisli category over a familiar Haskell monad?)
edit: I am not sure if this is actually category-theoretically correct, but what I was imagining in the parenthetical of question 2 was nontrivial definitions of delete :: a -> m ()
and split :: a -> m (a, a)
for some specific Haskell type a
and Haskell monad m
that satisfy Kleisli-arrow versions of the comonoid laws in the linked answer. Other examples of comonoids are still welcome.
Z_n
fora
and[]
form
, and my operators are:delete _ = []; split x = [(0, x), (1, x+1), ... (n-1, x+n-1)]
(all additions are modulo n). How do I check whether the laws are satisfied? Say I want to check thatidL $ first delete $ split x = x
, how do I lift it to the[]
monad? – n. 1.8e9-where's-my-share m.