5 ms·
I've applied the Monoid and Semigroup patterns often in Python and JS. Knowing about CT helps you leverage their properties (associativity, often commutativity
by tommikaikkonen 9y ago
I've applied the Monoid and Semigroup patterns often in Python and JS. Knowing about CT helps you leverage their properties (associativity, often commutativity, having an explicit identity element for a monoidal operation), and writing tests against those properties.
They're common patterns a lot of people use without knowing anything about CT, for example if you fold/reduce over a collection with an initial value, and the collection may be empty, you're looking at a monoidal operation. You can call the initial value a constant identity. Like sum, product.
If you fold/reduce over a collection where the collection may not be empty, and you need to use the first element as the initial value, you're looking at a semigroup operation. Like min/max/mean.
- platz 9y agoApplying semigroup in JavaScript is a wholly different enterprise than studying adjunctions, pullbacks, and the Yoneda lemma. I know we programmers like to call using Monoids "CT", to smash Things together with some associativity (those things existed in abstract algebra long before CT), but I don't think those things capture what CT is about or what the OP article is investigating.
- BoiledCabbage 9y agoSo after looking into Category Theory for a bit, it seems like everything CT that most people use (and I had wanted to learn) is covered in abstract algebra. Monoid / Semi-groups, algebraic properties. And an in an easier presentation than CT. What are some programming applicable Category Theory topics that aren't covered in abstract algebra?
- empath75 9y agoMonads.
- BoiledCabbage 9y agoNot to be pedantic, but if someone understands monoids well from abstract algebra and someone else says: "By the way, in addition to all the existing monoids you know (Ints under '+', strings, lists...), functions under function composition also form a monoid. Here's an example." Isn't that pretty much getting them to the same place? Do they really need a study of category theory?
- kmill 9y agoFunction composition is a monoid, but it is not a monad, even though the words sound similar. So it's not really getting them to the same place, but I'm not going to offer any opinion on whether someone needs to study category theory. Not quite function composition, but given a type a, (a ->) is a monad (the so called "reader monad"). We have return :: x -> (a -> x) return x = \a -> x (>>=) :: (a -> x) -> (x -> (a -> y)) -> (a -> y) m >>= f = \a -> f (m a) a (Incidentally, these are two of the Łukasiewicz axioms for propositional calculus.) It is a functor with fmap :: (x -> y) -> (a -> x) -> (a -> y) fmap f m = \a -> f (m a) In the case x=y, then fmap takes the monoid of functions on x to the monoid of functions on (a -> x). Venturing into more abstract territory, "a monad is a monoid in the category of endofunctors of a category C." (This has never helped me with understanding how to use monads in Haskell.) Basically, the choice of endofunctor is the type constructor for the monad, the unit map is `return` and the composition map is `join`.
- hiker 9y ago> return :: x -> (a -> x) > return x = \a -> x > > (>>=) :: (a -> x) -> (x -> (a -> y)) -> (a -> y) > m >>= f = \a -> f (m a) a >(Incidentally, these are two of the Łukasiewicz axioms for propositional calculus.) Also the K and S in SKI combinator calculus https://en.wikipedia.org/wiki/SKI_combinator_calculus https://en.wikipedia.org/wiki/SKI_combinator_calculus
- kmill 9y agoThe Wikipedia article mentions "The combinators K and S correspond to two well-known axioms". I wonder whether Schönfinkel and Curry had Łukasiewicz's axioms in mind when creating it? I'm finding it difficult to find the history of either the combinators or the axioms.