Thank you from Brazil! I got to functional programming through a practical way and I have been wanting to understand what is all the talk about category theory. Your course was a great introduction! I am looking forward the book and the follow up courses.
It's not merely that a monoidal category is strict if (a \otimes b) \otimes c = a \otimes (b \otimes c), it's that the associator and unitor maps are identity morphisms [in theory one could have equality of those objects but without the associator being the identity]. Also, the word "lax" should be treated with caution: usually, among category theorists, it signals that the structural morphism in question is not assumed to be invertible.
What does it mean to be a "tensor product"? What properties does it have? Are they necessary for the reasoning or any kind of "binary product-like" operation will suffice?
It's actually a tricky question. There is a formal definition of a tensor product using a universal property in a multicategory, but it's way too advanced for this course. So here it's just a bifunctor that defines a monoidal category. Mac Lane puts "tensor product" in quotation marks when he talks about monoidal categories.
There are two contexts where one is allowed to speak of tensors and tensor products : the first is physics and the tensor as the name indicates is a matrix of a variable number of dimensions that expresses the set of tensions a quantity expressed by a vector is subject to. Tensor products in a more abstract sense is the product of an array of m dimensions by an array of n dimensions to give one of n + m dimensions expressing for instance a combined tension in the world of physics.
I just finished this course and I thank you so much Mr. B Milewski for sharing this excellent series on CT. You made the lectures fun and easy to understand, particularly for developers like me transitioning from imperative to functional. Your lectures on Functors, Functoriality and the diagram chasing in Natural Transformations helped me understand and look behind the curtains when seeing some of the Haskell typeclass signatures. Looking forward to the next series. Thanks again.
I'm reviewing monads (videos 3.2, 10.1, and this one) and trying to get my intuition solid before progressing further in the third and current course. The view in this video still seems a little weird, a bit like having a dog inside a dog. Please correct any mistakes: A monad is an example of a monoid inside a monoid, specifically a monoid object M in a monoidal category. A monoidal category is a monoid whose elements are the objects, and whose operation is the tensor product between two objects. One of the objects is the unit, I. A monoid object M is similar to the single-object monoid introduced in video 3.1, with one key difference. It relies on a second object, namely the unit object I, to "pick" its unit element using the unit morphism η. Remember that the single-object monoid accomplished this with its identity morphism. (So what does the identity morphism of a monoid object "do"?) The operation of M is called μ, which is an endomorphism, just like it was for the single-object monoid. In particular, the monoidal category where a monad "lives" is the category of endofunctors. The tensor product is composition of endofunctors. Now I have a question: where is the special composition of a monad (as used in programming) encoded? In the tensor product M⊗M? And what about the way it's defined in category theory results in the composition being special?
Good stuff, but I am a little confused about something. This definition of a monoidal category, looks simpler than the definition of a monoidal category given in Wikipedia (as well as page 417 of your book), which has coherence conditions involving 4 objects. Are these definitions equivalent, or is there some difference between these definitions ?
@@DrBartosz Thanks. One more question, it is concerning a possible typo in Saunders Mac Lane's book (second edition, page 280, concerning single set representations of 2 categories). I understand if you don't respond, since it's outside the course, but I thought I'd better ask, since I bet you know, and it is really bugging me. My question is, is expression (8) a typo ? I thought it should be an equation, and if so what ? The interchange law ?
A monoid is associative with identity and a category is associative with identity. I think of this relation when I see monad is a monoid in the category of endofunctors.
Hope I get this right: mu and eta exist for all objects in the category of endofunctors?! If so, then all objects in this category are monads, aren't they?
@@BartoszMilewski But at the end (ruclips.net/video/GmgoPd7VQ9Q/видео.html) of the video you said "...pick one object in the category of endofunctors..." and you showed that mu and eta somehow "existed" for the object T. So this "picking" was already constrained?
Thanks for the great course! What I don't understand here, in the [C,C] we pick T as an object, but what T^2 would be? Is it another object with mu going from it to T, or something else? If it is another object, how T and T^2 are related in terms of composition? Can we pickup the composition of endofunctors from the category?
You had me until these last two lectures but somehow I lost it on the Monad sections. I still don't understand how a Monad can encapsulate both purity and some state but I'll have to re watch and see if I can work it out on paper following along again.
Slightly more abstractly, a monad is a lax functor from the terminal bicategory into your bicategory K. When K = CAT, this picks out a category (often just taken to be Set), an endofunctor on it, and two natural transformations. The coherence axioms for a lax functor reduce to exactly the axioms for a monoid object.
Bartosz Milewski Nice! And then if you view the monad as a diagram in your bicategory K, it's lax limit and colimit are precisely the eilenberg Moore and kleisli objects for the monad. Of course for comonads you take oplax functors instead of lax. Generalising slightly, but still being a special case of lax functors, a category enriched in a bicategory K is precisely a lax functor from an indiscrete 2-category on a class X. Indiscrete meaning every hom category is terminal. When K has only one object, you recover the definition for enrichment in monoidal categories.
So husk (the haskell category) is a small category, but we can use it to build higher level monoid categories, one of which is the category of endofunctors.
So an example from Hask of such an endofunctors composition would be [Maybe a] (or ([] . Maybe :: Type -> Type, if there type-level "."), and appropriate function mapping ("tensor product" of two of them, which is function composition "." here) is (fmap @([])) . (fmap @Maybe), is it? But Id (Maybe a) wouldn't be the same as Maybe (Id a), isn't it? Or is it up to isomorphism?
Composition of functors is defined in Haskell in Data.Functor.Compose . And, yes, it's up to isomorphism. You have to do some messy unpacking/repacking of data constructors.
I think I'm having a problem in understanding the "monoid in the category of functors" because I'm trying to visualize it in a similar fashion as one visualizes a monoid on sets. (Maybe the problem is that a monoid on sets is itself a category but maybe this is not the case for monoid on endo-functors). A monoid in sets is a category with a single object (*) and each element of the set is an arrow from * to * and the composition table of arrows is the same as the binary operation corresponding to the monoid. Besides, one of the arrorw correspond to the unit of the monoid and is the identity arrow. And this is very simple to visualize. Can we visualize similarly a monoid in the category of endo-functors? I'm trying to imagine a single objec category, named (*) and each arrow corresponding to an application of the endo-functor. So I have arrows for M, M^2, M^3, ... and even I can imagine an arrow for M^0 = Id. And the arrow table is given by composition. I think this construction can be done for any functor, not necessarily a monad. In a monad, given that mu: M . M -> M, does it mean I only have an arrow? Where is the identity arrow? I'm the last one is related to eta, but I don not know how. What I'm doing wrong? Is this "visualization" possible with a monad (a monoid in the category of functions)? Any help will be much appreciated and thanks for all you are doing to help us understand Category Theory and Functional Programming. Juan Manuel
I think the problem is that you are mistaking two different phenomena. To paraphrase Eugena Cheng, two different generalizations of the same idea can look very different, depending on the viewpoint you started with. Throughout this talk, monoid is meant to mean "monoid internal to some monoidal category". A monoid in the category of sets is a Set M with arrows 1 -> M, MxM -> M satisfying laws. It is in this sense that a monad is a monoid in [C, C]. It consists of a functor T with natural transformations id -> T, T . T -> T satisfying those same laws. On the other hand, you can indeed take the definition of a monoid to be a one object category, but that leads in a direction that is *significantly* more complicated and has little to do with what is discussed in this lecture (something to do with higher categories).
One exercise that might be helpful to you is to work out what monoids inside of other monoidal categories are. For example, try to work out what a monoid in the category of abelian groups is (where the product is ordinary tensor product). You can probably guess the answer, but try to actually verify it. If you are feeling particularly brave, you could try to convince youself that a monoid in CAT, the category of small categoies and functors, is precisely monoidal category.
This is "Down the rabbit hole" because I've serached for "abelian group" and "tensor product" and there is lots of things I've to learn. Thanks for the challenge.
Of couse! Hope I clarified things for you! If you aren't familiar with groups, I don't know how enlightening that example is going to be for you. It sounds like you might be from more of a cs background, in which case I'm not as qualified to comment on what would be a good exersise. (That said, the monoid in CAT example could still be useful to you). Since you are interested in category theory, I would definitely recommend learning some basic abstract algebra. Even if all you know is the definitions of groups, rings, fields, etc. and some basic examples, that could potentially provide you with a lot of useful intuition.
Hmmm... what do you call a monoid that isn't in the category of endofunctors? Does such a thing even exist? If not, why is the qualification given in the statement?
@@DrBartosz I was confused by these multiple definitions. Especially the difference between "category with 1 object" and "the monoidal category". Are all objects in the monoidal category called monoids? And if these objects are also endofunctors they are called Monads?
Your contribution to knowledge of developers all over the world is invaluable. I can't wait to read your recent book on CT
+1
The last minute of this is just Bartosz dropping the mic, so good.
On behalf of all lambda freaks - thank you for your lectures!
Lambda calculus and functional programming: the *only* *True* religion!
Thank you from Brazil! I got to functional programming through a practical way and I have been wanting to understand what is all the talk about category theory. Your course was a great introduction! I am looking forward the book and the follow up courses.
I've just finished this course and it was soooo great and helpful for me thank you Bartosz
A chapter of my life has been completed, thank you kind friend for sharing your wisdom, now I shall begin another one!
This feels like beating a Souls game!
Excellent Course! I worried I would never understand this stuff; going straight to part 2.
It's not merely that a monoidal category is strict if (a \otimes b) \otimes c = a \otimes (b \otimes c), it's that the associator and unitor maps are identity morphisms [in theory one could have equality of those objects but without the associator being the identity]. Also, the word "lax" should be treated with caution: usually, among category theorists, it signals that the structural morphism in question is not assumed to be invertible.
What does it mean to be a "tensor product"? What properties does it have? Are they necessary for the reasoning or any kind of "binary product-like" operation will suffice?
It's actually a tricky question. There is a formal definition of a tensor product using a universal property in a multicategory, but it's way too advanced for this course. So here it's just a bifunctor that defines a monoidal category. Mac Lane puts "tensor product" in quotation marks when he talks about monoidal categories.
There are two contexts where one is allowed to speak of tensors and tensor products : the first is physics and the tensor as the name indicates is a matrix of a variable number of dimensions that expresses the set of tensions a quantity expressed by a vector is subject to. Tensor products in a more abstract sense is the product of an array of m dimensions by an array of n dimensions to give one of n + m dimensions expressing for instance a combined tension in the world of physics.
I've just completed this list. Thank you very much for the course! The next will be part II.
This is for sure the best video I have ever seen.
I just finished this course and I thank you so much Mr. B Milewski for sharing this excellent series on CT. You made the lectures fun and easy to understand, particularly for developers like me transitioning from imperative to functional. Your lectures on Functors, Functoriality and the diagram chasing in Natural Transformations helped me understand and look behind the curtains when seeing some of the Haskell typeclass signatures. Looking forward to the next series. Thanks again.
*Dr* B. Milewski.
Only one word about explanation of monads: Perfect!
I'm reviewing monads (videos 3.2, 10.1, and this one) and trying to get my intuition solid before progressing further in the third and current course. The view in this video still seems a little weird, a bit like having a dog inside a dog. Please correct any mistakes:
A monad is an example of a monoid inside a monoid, specifically a monoid object M in a monoidal category. A monoidal category is a monoid whose elements are the objects, and whose operation is the tensor product between two objects. One of the objects is the unit, I.
A monoid object M is similar to the single-object monoid introduced in video 3.1, with one key difference. It relies on a second object, namely the unit object I, to "pick" its unit element using the unit morphism η. Remember that the single-object monoid accomplished this with its identity morphism. (So what does the identity morphism of a monoid object "do"?) The operation of M is called μ, which is an endomorphism, just like it was for the single-object monoid.
In particular, the monoidal category where a monad "lives" is the category of endofunctors. The tensor product is composition of endofunctors.
Now I have a question: where is the special composition of a monad (as used in programming) encoded? In the tensor product M⊗M? And what about the way it's defined in category theory results in the composition being special?
Correction: μ is not an endomorphism.
Great lecture, the only improvement I'd suggest is a clearer distinction between "Monoid" and "Monoidal Category"
You made it so clear, thanks, you're already helping a lot
Thank you so much. This series has been amazing.
Good stuff, but I am a little confused about something. This definition of a monoidal category, looks simpler than the definition of a monoidal category given in Wikipedia (as well as page 417 of your book), which has coherence conditions involving 4 objects. Are these definitions equivalent, or is there some difference between these definitions ?
I do mention coherence conditions in the book, although I don't list them. In such cases both Wikipedia and nLab are very reliable sources.
@@DrBartosz Thanks. One more question, it is concerning a possible typo in Saunders Mac Lane's book (second edition, page 280, concerning single set representations of 2 categories). I understand if you don't respond, since it's outside the course, but I thought I'd better ask, since I bet you know, and it is really bugging me. My question is, is expression (8) a typo ? I thought it should be an equation, and if so what ? The interchange law ?
@@RichardSouthwell Yeah, looks like a typo.
@@DrBartosz Yea I thought so. Thanks.
A monoid is associative with identity and a category is associative with identity. I think of this relation when I see monad is a monoid in the category of endofunctors.
Hope I get this right: mu and eta exist for all objects in the category of endofunctors?! If so, then all objects in this category are monads, aren't they?
No, they definitely don't. Natural transformations, in general, are pretty constrained. And these have to satisfy additional laws.
@@BartoszMilewski But at the end (ruclips.net/video/GmgoPd7VQ9Q/видео.html) of the video you said "...pick one object in the category of endofunctors..." and you showed that mu and eta somehow "existed" for the object T. So this "picking" was already constrained?
You couldn't help it with the title of the video, Bartosz... 😉
Thanks for the great course!
What I don't understand here, in the [C,C] we pick T as an object, but what T^2 would be? Is it another object with mu going from it to T, or something else? If it is another object, how T and T^2 are related in terms of composition? Can we pickup the composition of endofunctors from the category?
T^2 is T composed with T. Since it's also an endofunctor, it is an object in [C,C].
Thanks !!
I did try to understand all of it.
But maybe i understand 50% of it.
Butni will revisit it more
Thanka again
You had me until these last two lectures but somehow I lost it on the Monad sections. I still don't understand how a Monad can encapsulate both purity and some state but I'll have to re watch and see if I can work it out on paper following along again.
Slightly more abstractly, a monad is a lax functor from the terminal bicategory into your bicategory K. When K = CAT, this picks out a category (often just taken to be Set), an endofunctor on it, and two natural transformations. The coherence axioms for a lax functor reduce to exactly the axioms for a monoid object.
Yes, Paolo Capriotti has a very good blog post about it: www.paolocapriotti.com/blog/2015/06/22/monads-as-lax-functors/index.html .
Bartosz Milewski Nice! And then if you view the monad as a diagram in your bicategory K, it's lax limit and colimit are precisely the eilenberg Moore and kleisli objects for the monad. Of course for comonads you take oplax functors instead of lax.
Generalising slightly, but still being a special case of lax functors, a category enriched in a bicategory K is precisely a lax functor from an indiscrete 2-category on a class X. Indiscrete meaning every hom category is terminal. When K has only one object, you recover the definition for enrichment in monoidal categories.
I didn't know that.
So a monoid C, despite having only one object, can multiplied to itself: [C,C], to create a multitude of functors, thus creating a new category.
So husk (the haskell category) is a small category, but we can use it to build higher level monoid categories, one of which is the category of endofunctors.
It's actually called "Hask" wiki.haskell.org/Hask
@@XGD I like Husk better! xD
Amazing course, thank you!
So an example from Hask of such an endofunctors composition would be [Maybe a] (or ([] . Maybe :: Type -> Type, if there type-level "."), and appropriate function mapping ("tensor product" of two of them, which is function composition "." here) is (fmap @([])) . (fmap @Maybe), is it? But Id (Maybe a) wouldn't be the same as Maybe (Id a), isn't it? Or is it up to isomorphism?
Composition of functors is defined in Haskell in Data.Functor.Compose . And, yes, it's up to isomorphism. You have to do some messy unpacking/repacking of data constructors.
@@BartoszMilewski Thank you a lot for such a great tutorials! And for the help!
It as been a while and I am too afraid to ask the meaning of the eta morphism: in the notation eta: (() -> a. How is it called the unit morphism.
It's called unit because of the unit laws.
I think I'm having a problem in understanding the "monoid in the category of functors" because I'm trying to visualize it in a similar fashion as one visualizes a monoid on sets. (Maybe the problem is that a monoid on sets is itself a category but maybe this is not the case for monoid on endo-functors).
A monoid in sets is a category with a single object (*) and each element of the set is an arrow from * to * and the composition table of arrows is the same as the binary operation corresponding to the monoid. Besides, one of the arrorw correspond to the unit of the monoid and is the identity arrow. And this is very simple to visualize.
Can we visualize similarly a monoid in the category of endo-functors? I'm trying to imagine a single objec category, named (*) and each arrow corresponding to an application of the endo-functor. So I have arrows for M, M^2, M^3, ... and even I can imagine an arrow for M^0 = Id. And the arrow table is given by composition. I think this construction can be done for any functor, not necessarily a monad.
In a monad, given that mu: M . M -> M, does it mean I only have an arrow? Where is the identity arrow? I'm the last one is related to eta, but I don not know how.
What I'm doing wrong? Is this "visualization" possible with a monad (a monoid in the category of functions)?
Any help will be much appreciated and thanks for all you are doing to help us understand Category Theory and Functional Programming.
Juan Manuel
I think the problem is that you are mistaking two different phenomena. To paraphrase Eugena Cheng, two different generalizations of the same idea can look very different, depending on the viewpoint you started with.
Throughout this talk, monoid is meant to mean "monoid internal to some monoidal category". A monoid in the category of sets is a Set M with arrows 1 -> M, MxM -> M satisfying laws. It is in this sense that a monad is a monoid in [C, C]. It consists of a functor T with natural transformations id -> T, T . T -> T satisfying those same laws.
On the other hand, you can indeed take the definition of a monoid to be a one object category, but that leads in a direction that is *significantly* more complicated and has little to do with what is discussed in this lecture (something to do with higher categories).
One exercise that might be helpful to you is to work out what monoids inside of other monoidal categories are. For example, try to work out what a monoid in the category of abelian groups is (where the product is ordinary tensor product). You can probably guess the answer, but try to actually verify it.
If you are feeling particularly brave, you could try to convince youself that a monoid in CAT, the category of small categoies and functors, is precisely monoidal category.
Thanks for the answer. I was trying to make my life harder by trying to visualize the monad as a single object category.
This is "Down the rabbit hole" because I've serached for "abelian group" and "tensor product" and there is lots of things I've to learn. Thanks for the challenge.
Of couse! Hope I clarified things for you!
If you aren't familiar with groups, I don't know how enlightening that example is going to be for you. It sounds like you might be from more of a cs background, in which case I'm not as qualified to comment on what would be a good exersise. (That said, the monoid in CAT example could still be useful to you).
Since you are interested in category theory, I would definitely recommend learning some basic abstract algebra. Even if all you know is the definitions of groups, rings, fields, etc. and some basic examples, that could potentially provide you with a lot of useful intuition.
Which law do you major in? Monadic Law.
This shit just got intense))
Easy-peasy
Hmmm... what do you call a monoid that isn't in the category of endofunctors? Does such a thing even exist? If not, why is the qualification given in the statement?
I did define a general monoid, first as a single-category object, then as an object in a monoidal category.
Okay, thanks Bartosz. I probably need to go over this and other material a number of times more, although it is slowly becoming clearer to me.
@@DrBartosz I was confused by these multiple definitions. Especially the difference between "category with 1 object" and "the monoidal category".
Are all objects in the monoidal category called monoids? And if these objects are also endofunctors they are called Monads?
@@PunitSoni00 No, consider that Hask is a monoidal category and not all types are monoids.