
Why are monoidal categories interesting? - weinzierl
https://jvns.ca/blog/2019/03/26/what-are-monoidal-categories/
======
leshow
> I don’t know whether this particular thing really has anything to do with
> programming, I just remembered I thought it was cool.

There's so many cool things related to programming & monoids.

For example, monoids are parallelizeable. Since they are associative, you can
group monoids arbitrarily, then use their monoidal operation to get your final
result, think MapReduce, or a parallel fold operation.

Sorting operations are monoidal (think merge sort), sums, products, so many
cool things. There is a huge amount of application to computing.

~~~
mlthoughts2018
I am probably wrong, but I think all the examples you mention only rely on
associativity, and you’re essentially talking about why fold / reduce can be
parallelized (literally a parallel reduction).

For example, just make up some associative operation with no identity element.
Imagine a string binary operator that prepends the character ‘a’ to the second
operand, then concatenates them.

    
    
        f(‘foo’, ‘bar’) = ‘fooabar’
    
        x `f` y `f` z = ‘{x}a{y}a{z}’ 
        = x `f` (y `f` z)
        = (x `f` y) `f` z
    

but no string e can result in e `f` x == x, so there’s no identity and so no
monoid arises from this.

~~~
leshow
There is a requirement for identity, take sorting for example, you need to be
able to sort the empty set. It's a monoidal operation.

The same is true for folds:

    
    
        fold(xs) = fold(xs ++ []) = fold(xs) ++ fold([])
        fold(xs) = fold([] ++ xs) = fold([]) ++ fold(xs)

~~~
mlthoughts2018
There is no monoid type requirement for fold. See the type signature in
Haskell (where Monoid happens to be used for fold despite not being necessary)
vs Scala (which does not require a monoid) for example. Applying fold to an
empty argument has nothing to do with monoidal identities, for example you
could just specify what the “seed” result should be (like with Python’s reduce
function).

~~~
leshow
Have a look at this blog post, it contains the bit I got that fold description
from:

[https://philipnilsson.github.io/Badness10k/algebraic-
pattern...](https://philipnilsson.github.io/Badness10k/algebraic-patterns-
monoid/)

Back to my first post, I don't think it's not wrong to describe these
operations as monoidal. Or to say that a monoidal operation implies something
can be run in parallel, this whole thing feels a bit pedantic.

edit: I don't know how you can say monoids for lists have nothing to do w/
empty lists considering the definition is literally:

    
    
       -- Identity laws
       x <> mempty = x
       mempty <> x = x
    

Which is exactly what I posted before

~~~
leshow
should read: "It's not wrong to describe these operations as monoidal..."

------
dxbydt
6 years ago, when HN was way more relaxed & laidback, someone posted my story
about monoids. It stayed on the HN front page for like a whole day !!! (which
these days is next to impossible)

Anyways, here’s that monoid parable -
[https://news.ycombinator.com/item?id=5179410](https://news.ycombinator.com/item?id=5179410)

------
heinrichhartman
I have high regards for Julia, but I am a little sad to see so little meat
behind this promising title. As we find out at the very end:

> I don’t know whether this particular thing really has anything to do with
> programming, I just remembered I thought it was cool.

Also, I don't really get the main point:

> tensor [Monoidal] categories are about proving (or defining) things with
> pictures

You could say that about Category theory as a whole already. E.g. "A product
is a space which makes this diagram 'universally' commutative.". No?

~~~
skywhopper
Julia often writes pieces that are just partial captures of a few steps in
figuring something interesting out, and which don't come to a conclusion per
se. So I don't really understand your critique.

I'm not seeing this as any different than her typical articles, except that in
this case I know next to nothing about the topic and so from the start I was
lost.

Her first sentence and her second paragraph address your complaints, anyway.
We didn't "find out" that this was just her talking about something cool at
the end. Not only did she intro the piece with saying as much, but that's the
premise of her entire blog!

------
yakshaving_jgt
I always enjoy a good Julia Evans article, and this one is no different. She
has a very approachable, personable way of explaining technical things, which
is missing from many monoid (and related) tutorials.

I'm confused by this opening line though:

> Monoidal categories are also called “tensor categories” and I think that
> term is a little less confusing

Why is that? What is special about the word "monoid" that makes it more or
less confusing than "tensor"?

~~~
phlakaton
To the contrary, when I think "monoid" I think good old nonnegative integers
and addition, or positive integers and multiplication, or any of a half-dozen
really easy-to-understand examples.

Tensors... what the heck are those? Like matrices, but _more_ complicated, you
say? Thanks, but I'll stick with my basic monoids over here. :-)

The confusion between monoids and monads is perhaps unfortunate (even if the
similarity is quite intentional, because technically monads are a particular
kind of monoid), but easily sorted out and not much worse than having to
distinguish between the nuts in your pantry and the Nutella.

~~~
ginnungagap
You can think of a tensor as "an element of a tensor product" (just like a
vector is "an element of a vector space") and look at the definition of a
tensor product via its universal property, it basically turns bilinear maps
into linear maps. This universal property is elegant and immediately gives the
Hom-tensor adjunction, but to show that tensor products satisfying it actually
exist you'll need an explicit construction, which can be done by quotienting a
free module. This explicit construction might look unintuitive at first, but
you're really quotienting by the minimal relations required for the
"bilinearity" property of tensors to work out

~~~
JadeNB
I think this is a fantastic definition of what tensors are for mathematicians,
but I think it is likely to be not very helpful for someone whose perspective
is:

> Tensors... what the heck are those? Like matrices, but _more_ complicated,
> you say? Thanks, but I'll stick with my basic monoids over here. :-)

If matrices are the limit of your tolerance for complication, bilinear maps
probably aren't intuitive tools for you.

------
drablyechoes
Fun fact: a monoid is a category with one object.

~~~
JadeNB
A monoid is (realisable as) the _set of morphisms of_ a category with one
object ….

