Just because I clicked on this video and already knew what a Monad was means I am itching for a fight. I mean I am itching for a fight, but not about Monads.
Has it worked? Have you converted? It's only a matter of time. (Also, this puts you in one of the first two categories: UA-cam is your category theory/functional programming friend)
Dude, this was a banger video. Unironically a great explanation of the state monad too - seeing the parameter list and return type change was EXACTLY what I needed to make this idea click :)
Some time last year I decided it would be fun to sit down and understand the 'monoid in the category of endofunctors' definition. It took 3 days on my whiteboard and at the end, it just means a functor with join and pure satisfying the unit and associativity laws, and provides no further insight. I was right though, it was fun.
Yep, exactly! fmap :: functorial join :: multiplication ret :: unit While "monoid in a category of endofunctors" is really nice for never forgetting the axioms of a monad, it definitely doesn't help with understanding what a monad's all about.
An example of this in algebraic geometry: Let Sch be the category of schemes, and CRing^op be the opposite category of commutative rings, then the global section functor Γ admits a right adjoint which is called Spec, which takes a commutative ring to its prime spectrums. As general consequences of pair of adjoint functors the composition Spec(Γ(-)) has the structure of a monad. For a scheme S, there is a canonical affinization map S -> Spec(Γ(S)); and Spec(Γ(Spec(Γ(-))) = Spec(Γ(-)) is always true because Γ(Spec) is (equivalent to) the identity by construction of Spec. In this case, an algebra over this monad is nothing but an affine scheme.
Idempotent monads like this (arising from a fully faithful right adjoint) are an interesting subclass, since the category of algebras is a full subcategory of the original category (whereas you normally expect a category of algebras to be in some sense "bigger" than the original). However, this special property makes the "algebra" aspect of monadicity harder to appreciate in this case. For example, the category Grp of groups is monadic over sets, and this reflects how groups are a kind of algebraic structure over sets (like my linear algebra example). On the other hand, the category Ab of abelian groups is also monadic over Grp, but since this arises from an idempotent monad, Ab is a full subcategory of Grp, making it weirder to see it as expressing abelian groups as an algebraic structure over groups. Of course, this isn't to say there is no algebraic structure going on here: abelian groups are precisely the groups with an additional compatible group structure (by Eckmann-Hilton). Your example is similar in this respect: CRing^op is already the category of affine schemes, and it's kinda strange to view affine schemes as "schemes with some kind of algebraic structure", but you *can* do it.
@@SheafificationOfG Yea there are many examples of idempotent monads arising in algebraic geometry. For example, if X is a variety with ring of functions R, then the adjunction R-mod QCoh(X) given by localization and global sections gives an idempotent monad. This realizes a subcategory of QCoh(X) as R-module, and I believe applying Barr-Beck theorem tells you that this is an equivalence iff X is affine.
I'm not gonna lie, it did take me some work to get to the point where I could actually understand "Monoid in the category of endofunctors" but now that I got there, it kind of is the most concise way for me to represent the information in my mind
I didn’t completely follow, especially nearing the end, but I’m going to rewatch when I’m in a better frame of mind. This is very very good stuff man I always love to see high level math videos on UA-cam that aren’t just 1hr long lectures. Keep up the good work!
I'm in Category IIIa. I know what a monad is, and itching to tell the categorists and functional programmers to please keep the noise down, I'm trying to get some work done here!
I don't think I understood work in this video, as a category 5 viewer, youtube recommendation, then I just watched for all the memes. I feel like you need a Master's in mathematics to understand something from this video.
Rather knowledge in maths AND programming. As someone with a maths degree, I can tell you you don't normally deal with the concept of monad, unless you actively pick the courses which do.
I'm from the 5th category of people who are using jet bundles a lot in their day to day life and therefore need an explanation what a monad is to understand what a co-monad could be. But for real, great video, love your style and I feel I finally understood something about monads. Thanks a lot!
Okay as a person that knows about monads and jet bundles i do not immediately see what comonads hage to do with jet bundles, or are jet bundles comonads? (Its 00:18 and i have not the brain capacity to figure this out without paper)
@@SheafificationOfG sure: Let B be one of the bases for the vector space of continuous functions R→R guaranteed by the axiom of choice. By Zorn's lemma we may (through torturous restructuring into any other arbitrary form of the AoC) select basis B. Thus we now have a basis for the aforementioned space. QED.
love the video! As a tip for audio quality (because microphones are expensive), it’s a great trick to record the white noise in the room you’re recording in, and put it over any blank spots in the script. That way the audio-to-no-audio transformation isn’t so harsh. Subbed!
If your recording software supports VST plugins you can install Reaper and use ReaFir in subtract mode to remove the background noise. Just let it build the noise profile for few seconds and it's almost gone on all recordings.
You explained everything super clearly. Even though this is easily the highest level, I've heard anyone go into monads, I actually understood. Can't wait for the next upload!
Geez. I learned both FP+Formalization (under the umbrella term of 'Programming Language') and pure math, and was thinking about all the foundation stuffs from time to time from my enjoyment. You are very strong at explaining the _intuition_ behind it as clear as possible while getting as deep as it can get in understanding. Much thanks and I look forward for future videos!! Suggestion that you can freely ignore: Is the set X of 'computable' real numbers countable? There is only a countable number of programs, so it should be countable. Now by enumerating X and using the Cantor diagonalization, can't we get contradiction by finding a computable number outside X? (A counterargument gives a resolution of Halting problem) Now how about the set of 'defineable' real numbers? There is only a countable number of math statements. How about we do the Cantor diagnoalization again here? I'm saying all this without clarity and only handwaiving... what I'd like to see is a crystal clear clarification around those issues if you get what I mean.
Thanks! The angle on Cantor's diagonalisation to prove that the computable numbers are not computably enumerable (despite being countable) is definitely cute! I'll see if it fits with some topics I might want to cover down the road!
I've seen a lot of monad-explainers on youtube, but this is the first one I feel I really understood, so thanks for that! What would you recommand to start learning category theory? Or perhaps to learn more about applications of cat in cs? (Btw, I AM assuming the axiom of choice, and in fact in every waking moment of my life I am consciously assuming it!)
Thanks so much, I appreciate it (except for the part where you choose the axiom of choice)! As for category theory recommendations: I've heard that "Category Theory for Programmers" (github.com/hmemcpy/milewski-ctfp-pdf) is good, but I've personally never read it. I studied category theory purely as a mathematical endeavour, mainly in its intersection with algebraic topology, so I can't say my curated advice would be too valuable to someone on the CS side, though hopefully the book reference is useful.
Explaining monads in fp as just being a type that allows you to compose an effect when used on any other arbitrary type instantly made perfect sense compared to all the other explanations I've heard over the years when trying to grok it
The only thing that would make this even more complete would be discussion on monads in philosophy and in physics. Also I find it ridiculous that mathematicians just went ahead and said to itself, "I know there is 5 times 5, and there is 5 times X, but what if I did 5 times apple?" and just, invented a whole terminology for that. Preschooler-level creativity - which is creativity of the highest order.
@@SheafificationOfG Oh hey, thanks for commenting! If you want, you could describe a Monad as being a "perfectly unified/most basic thing/concept, often which if the original Thing." Rather important in Greek philosophy. Plus, a lot of religions tend to think of God as a monad. It would be cool to see how this relates to math, including set theory and ideas of infinity (for example, you can use set theory to prove God cannot make a rock he can't lift, since that would involve making another God, or God being a self-defined thing with no need to have been created, but that's a whole discussion). I'd say the best advice is just to browse wikipedia on this and absorb whatever you can, and when you see something that looks like it intersects with your fields, dive into it properly. As for physics, I was thinking in terms of singularities, eg black holes, which arguably are unified point in the universe where the density is arguably infinite. You'll probably find making a vid on that much easier.
@@penand_paper6661 Ah, that description of the philosophical monad is roughly what I gathered from my 10s of browsing (definitely not my wheelhouse). Do physicists really refer to singularities as monads?
@@SheafificationOfG Truthfully, physics is not my area of expertise. However, I once saw the term used to describe singularities. I think you'd have a better time looking into the physics, as the math you worked with in the vid might have an application somehow there. (And since physics is basically applied maths.)
As an undergraduate interested in categorical logic, I'm so glad that I clicked this video, really well done! Love the concise yet accurate language and the funny presentation style, can't wait to see more videos! Also just a curious question: judging from your username, I would assume you have some background in topos theory? If so, how do you make sense of Beck monadicity theorem and Pare theorem (the latter says that for every elementary topos, the "powerobject" functor is monadic)? I never feel comfortable with them.
Regarding Beck monadicity: if you're willing to accept that a "monad" is a general way of encoding a flavour of "algebraic structure" on objects of a certain category, then Beck's monadicity theorem is a recognition theorem for when you can view objects of one category as "objects of another category with algebraic structure". This perspective also gives a bit of intuition for the conditions on a functor U : C -> D to be monadic: 1. U having a left adjoint establishes that you can use the putative algebraic structure to *generate* an algebra from an "unstructured" object in D (analogous to "formal linear combinations" generated over a set in the video), and it identifies which objects of C are freely-generated. 2. U creating coequalisers of U-split pairs reflects the fact that a general algebra admits a presentation via "generators and relations" (like a free resolution of a ring; in fact, this is a good place to draw intuition). Regarding Paré's result on the monadicity of the contravariant power-object functor, I think a good starting point for drawing intuition is to look at the category of Sets. Again, if we take "monadicity" of U : C -> D to mean "C is the category of objects of D equipped with a certain kind of algebraic structure", then understanding the monadicity of \Omega : E^op -> E amounts to understanding how to view objects of E^op as objects of E with algebraic structure. For sets, (classically) we have an equivalence of categories between Set^op and the category CABA of "complete atomic Boolean algebras", from which it's apparent what algebraic structure is encoded by the contravariant powerset functor. This gives an impression of what's going on in general (though, you have to let go of LEM, so you don't get "Boolean algebras").
Funny and impressive explanation. I did not expect you to get into Kleisli vs Eilenberg-Moore. It's a choice of technical presentation that I think sacrifices intuition, but it's equivalent to the induced T-modules versus *all* T-modules. I'd always felt like the programmers were using monads in a weird way and this helped elucidate that. I still don't see how that first joke about a monad being a single object endofunctor enriched category actually works though - that's *any* category considered as a singleton subcategory of the category of categories. Feels like it's a homage to the joke definition of a group as a single-object groupoid but here I don't see the equivalence.
Just like how a monoid is a category with one object, a monoid object in V is equivalent to a V-enriched category with one object. So, since "a monad is a monoid in the category of endofunctors", it follows that a monad is an endofunctor-enriched category with one object. But yes, it is a bit of an homage to the group vs groupoid joke :) Also, a category is not determined by its corresponding singleton subcategory of Cat. For example, both the initial and terminal objects in Cat have equivalent endofunctor categories.
@SheafificationOfG Ah, I see where my sleep deprived brain went wrong - I made the classic newbie mistake of thinking of the V-enrichment in terms of each morphism being an object of V rather than replacing the hom-space itself by an object of V. Now that I've had lunch and a nap it makes a lot more sense.
I am my own functional programming friend, and I also have no idea what a monad is. Though understanding 20% of this video is as close as I've ever been
after learning a bunch of mathematical logic and getting into haskell and lambda caluclus and type theory, this whole thing now makes a lot of sense. (i was an expert c++ programmer, so i'm familier with impure functions or functions that obfuscate their state).
tbh I'm friends with monads from both points of view so I just came here for the memes; but the relation FP:Algebra ≈ Kleisli:EM was an unexpected epiphany! 🤯 ... then I started wondering what the dual of an epiphany is and ended up realizing I still haven't found the time to play Danganronpa T_T anyway, subbed 👍
This was actually very helpful and understandable. As a mathematician, I felt vindicated by the ending. I can also assure you, every vector space is freely generated. Can you imagine living in a world where some K-vector spaces are neither injective nor projective ? Having a nontrivial cohomological theory for K-vector spaces ? Have you thought of the ramifications that jumpscare-denying AC can have on poor unsuspecting algebraic geometers just chilling around ? Kind of irresponsible.
Good luck with your channel! This is great content. Personally, I'd use less distracting images while on such a denser subject (i know the subject matter, but still had to pause a few times or scroll back).
A monad is a monoid in the category of endofunctors. A monad is a monoid in the category of endofunctors. A monad is a monoid in the category of endofunctors. A monad is a monoid in the category of endofunctors. A monad is a monoid in the category of endofunctors. A mo
7:10 I had this exact moment with path algebras of quivers... like what does it mean to 'add' two paths together if they are in disjoint parts of the quiver....?
Im from the category of people that accidentally clicked a FP video and the algorithm has been sandblasting my face with FP related vids ever since last week
I think the disagreement over what a function is is not so much its domain and codomain, but rather that a function in computers describe an algorithm to be run, i.e. a procedure. A mathematical function is not a procedure to run or to be evaluated, it just is. It is a common misconception that expressions like sin(e/pi) do not have an exact value, but indeed it is. sin(e/pi) is exactly sin(e/pi). What is commonly meant is that it isn't a computable or "calculable" number. But mathematical expressions or functions are not *procedures*, which is usually how more laymen people, applied mathematicians and computer scientists tend to view them.
Is it really common to believe that sin(e/pi) doesn't have an exact value? It may not have a closed form, but this number is "computable" (in the sense that there is an algorithm for computing sin(e/pi) to whatever desired precision in finite time). The discrepancy is definitely that mathematics views functions as a unique abstract association of an output (in the codomain) to any input (in the domain), whereas procedural programming views functions as an abstraction for parameterised computation. The point for introducing monads is just that they offer a way of reconciling the latter so that it can be studied as a mathematical (i.e., "pure") function, and remarkably this can be done by having a monad modify the codomain according to the type of effect the procedure has when executed. However, this is not to say that the discrepancy between functions in maths and CS is a matter of the choice of codomain. Monads are, of course, not the "be-all and end-all" of encoding procedures as (pure) functions: monads are only capable of encoding the "computational effects" of a procedure. It's not necessarily ideal for encoding so-called "computational context" (which affect the behaviour of the procedure)---such things are better suited to comonads.
@@SheafificationOfG And by "an abstraction for parameterised computation" you mean a procedure that eventually produces the desired output. I am arguing that this procedure-based view is a much more fundamental disagreement rather than the domain and codomain.
@@markusklyver6277 I agree with you that the procedural nature of functions in programming is definitely the more fundamental thing, but I'm just confused by what you mean regarding a "disagreement in co/domain"... I don't recall saying something along this line in the video. I (hopefully) didn't claim that all discrepancies can be resolved by having procedures appeal to co/monads to become pure functions, but the focus of the video was on monads, so naturally the discrepancy between math/cs functions that's important to me in this case is the presence of computational effects (which, of course, fall out of the procedural nature of these functions).
Monads are *not* monoids in the category of endofunctors... rather, if *C* is _any_ 2-category, then a monad is a monoid in the category *C*(A,A) for an object A in *C*.
I am of the category of people that try to understand what Gotfiried Wilhelm Leibniz and Baroch Spinoza have in common, who starts actively sweating, whenever I see a depiction involving more than 3 mathematical signs in a sentence.
"If you are a functional programmer, you are interested in the category of sets where the maps from X to Y are the pure functions from X to T(Y)" Can someone explain what this means? Does this mean that (maps from X to Y) map (by the category) to (the pure functions from X to T(Y))? Or am I misunderstanding categories completely
Great video! I feel like this is the closest I've ever gotten to understanding fmap, join, and bind. I'm just… not *quite* there. I'm also unsure what monads can do that generically-typed structs (like std::pair) can't. Finally, the example used to demonstrate fmap glosses over what happens if the division function fails; it feels as though fmap is told "just assume no errors will occur and operate as if the types were X and Y instead of T(X) and T(Y)".
Thanks! Regarding your comment on generically-typed structs vs monads, I think the misconception is that monads are more of a "design pattern" than a "data structure". There are many ways you can *implement* a monad. For example, std::optional *is* an implementation of the Maybe monad (where the "new element" is std::nullopt). Of course, you can go your whole life without thinking about std::optional as a monad (or without even using std::optional, really), but the monad perspective can help you navigate your usage of std::optional. For example, if we use the pure implementation of division (4:33), how do we pass its output to is_pos? C++ will complain if you just pass a std::optional into is_pos, so you need to write a wrapper for is_pos to only deal with the "float part": if (input.has_value()) { return is_pos(input); } else { return std::nullopt; } This wrapper is exactly fmap(is_pos). In particular, what you say about fmap really is what happens: fmap expresses how pure functions are completely unaware of any computational effects. If the input to fmap(is_pos) were an error (due to division by zero, say), the result of fmap(is_pos) is the same error. In particular, fmap isn't supposed to do anything too deep, and is just there to "correct the input/output types" of a pure function.
@@SheafificationOfG this makes a lot of sense for "programming on rails" monads like maybe, but what does fmap do with the state monad? My immediate guess would be that it executes the pure function then discards the state output, but that implementation removes logic which sounds silly
@Seltyk in general, fmap "passes effects along" through pure functions. If you have a pure function f : X -> Y, then fmap for the state monad transforms this function into a map Funcs(S, X x S) -> Funcs(S, Y x S). In other words, you can imagine the input of fmap(f) being "a value x that depends on state and, when obtained, alters the state", so the output is "the value f(x) that depends on the state and, when obtained, alters the state [where the effect on state is done when finding x before plugging into f]". If you try to use a pure function f : X -> Y and construct a function fmap(f) of the correct type, this is essentially the only natural way to do it. I hope this helps!
um... does a monad that returns a placeholder value consistent with the expected return value type, on failure, instead of throwing, still qualify as a maybe?
The maybe monad *always* extends a type to have a new element. If your implementation of division returns 0, say, when dividing by zero, then you actually just have a good old-fashioned pure function with no computational effects at all.
I'm here thanks to the algorythm. I switched from math to cs like 2 years ago. I love math more, but it just didn't work out and it was on my part that I didn't bring more into thsi relationship.
@@SheafificationOfG The funny thing is, I haven't even watched far enough to hear you say that yet since I've been busy, I just came from the followup video to this one and had to say it 🤣. It was purely coincidental and reactionary lmao
Also, I love the explanations. Yet I retain the idea that monads are simply a box I put my object in and then leave a note on the box for the next time somebody might want that object.
I do not know what a monad is or why im here but im glad i am
Just because I clicked on this video and already knew what a Monad was means I am itching for a fight. I mean I am itching for a fight, but not about Monads.
I've got my ad hominem ready for whenever you are (whatever the fight is about).
5th category, youtube algorithm is trying to get me interested in math.
Has it worked? Have you converted? It's only a matter of time.
(Also, this puts you in one of the first two categories: UA-cam is your category theory/functional programming friend)
@SheafificationOfG ill know in a few months. May or may not be pursuing a math minor rn.
@@badabing3391 let's goooooooo
@SheafificationOfG dont get too excited, im still an engineer foremost 😅
im in the 6th category, i have to learn haskell in university
As a physicist (person who can't math or program), this is lovely. I understood like 75% of each part
Fantastic video
I never realized how important it was to understand why axioms were chosen
Dude, this was a banger video. Unironically a great explanation of the state monad too - seeing the parameter list and return type change was EXACTLY what I needed to make this idea click :)
Glad to hear I could manipulate the state of your understanding (in a good way)!
This is excellent content and a lot better explained than a number of more "serious" sounding YT math channels.
Thank you so much!
0:34 you just wiped my database clean out. Thanks a lot.
Some time last year I decided it would be fun to sit down and understand the 'monoid in the category of endofunctors' definition. It took 3 days on my whiteboard and at the end, it just means a functor with join and pure satisfying the unit and associativity laws, and provides no further insight. I was right though, it was fun.
Yep, exactly!
fmap :: functorial
join :: multiplication
ret :: unit
While "monoid in a category of endofunctors" is really nice for never forgetting the axioms of a monad, it definitely doesn't help with understanding what a monad's all about.
This was the best explanation I heard on Monads, I hope you continue to make videos like this one
An example of this in algebraic geometry: Let Sch be the category of schemes, and CRing^op be the opposite category of commutative rings, then the global section functor Γ admits a right adjoint which is called Spec, which takes a commutative ring to its prime spectrums. As general consequences of pair of adjoint functors the composition Spec(Γ(-)) has the structure of a monad. For a scheme S, there is a canonical affinization map S -> Spec(Γ(S)); and Spec(Γ(Spec(Γ(-))) = Spec(Γ(-)) is always true because Γ(Spec) is (equivalent to) the identity
by construction of Spec. In this case, an algebra over this monad is nothing but an affine scheme.
Idempotent monads like this (arising from a fully faithful right adjoint) are an interesting subclass, since the category of algebras is a full subcategory of the original category (whereas you normally expect a category of algebras to be in some sense "bigger" than the original).
However, this special property makes the "algebra" aspect of monadicity harder to appreciate in this case.
For example, the category Grp of groups is monadic over sets, and this reflects how groups are a kind of algebraic structure over sets (like my linear algebra example). On the other hand, the category Ab of abelian groups is also monadic over Grp, but since this arises from an idempotent monad, Ab is a full subcategory of Grp, making it weirder to see it as expressing abelian groups as an algebraic structure over groups. Of course, this isn't to say there is no algebraic structure going on here: abelian groups are precisely the groups with an additional compatible group structure (by Eckmann-Hilton).
Your example is similar in this respect: CRing^op is already the category of affine schemes, and it's kinda strange to view affine schemes as "schemes with some kind of algebraic structure", but you *can* do it.
@@SheafificationOfG Yea there are many examples of idempotent monads arising in algebraic geometry. For example, if X is a variety with ring of functions R, then the adjunction R-mod QCoh(X) given by localization and global sections gives an idempotent monad. This realizes a subcategory of QCoh(X) as R-module, and I believe applying Barr-Beck theorem tells you that this is an equivalence iff X is affine.
me first year in stem, with one abstract algebra course: hmm, impressive, very nice
@@SheafificationOfG so an idempotent monad is one where the multiplication map is an isomorphism? or something like that?
@@SultanLaxeby Yep, that's exactly right!
I'm not gonna lie, it did take me some work to get to the point where I could actually understand "Monoid in the category of endofunctors" but now that I got there, it kind of is the most concise way for me to represent the information in my mind
But, admittedly I know the functional programming perspective primarily, and I'm trying to expand more into the math
I didn’t completely follow, especially nearing the end, but I’m going to rewatch when I’m in a better frame of mind. This is very very good stuff man I always love to see high level math videos on UA-cam that aren’t just 1hr long lectures. Keep up the good work!
0:16 My brother in Christ, I just like math
I'm in Category IIIa. I know what a monad is, and itching to tell the categorists and functional programmers to please keep the noise down, I'm trying to get some work done here!
I don't think I understood work in this video, as a category 5 viewer, youtube recommendation, then I just watched for all the memes. I feel like you need a Master's in mathematics to understand something from this video.
Rather knowledge in maths AND programming. As someone with a maths degree, I can tell you you don't normally deal with the concept of monad, unless you actively pick the courses which do.
I fully expected a Morpheus quote at 1:50.
"Unfortunately no one can be told what the Monad is. They have to see it for themselves."
I'm from the 5th category of people who are using jet bundles a lot in their day to day life and therefore need an explanation what a monad is to understand what a co-monad could be.
But for real, great video, love your style and I feel I finally understood something about monads. Thanks a lot!
Okay as a person that knows about monads and jet bundles i do not immediately see what comonads hage to do with jet bundles, or are jet bundles comonads? (Its 00:18 and i have not the brain capacity to figure this out without paper)
9 subscribers chad lord. make it 10.
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠛⠋⠉⠈⠉⠉⠉⠉⠛⠻⢿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⡿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⢿⣿⣿⣿⣿
⣿⣿⣿⣿⡏⣀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿
⣿⣿⣿⢏⣴⣿⣷⠀⠀⠀⠀⠀⢾⣿⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠈⣿⣿
⣿⣿⣟⣾⣿⡟⠁⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣷⢢⠀⠀⠀⠀⠀⠀⠀⢸⣿
⣿⣿⣿⣿⣟⠀⡴⠄⠀⠀⠀⠀⠀⠀⠙⠻⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⣿
⣿⣿⣿⠟⠻⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠶⢴⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⣿
⣿⣁⡀⠀⠀⢰⢠⣦⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣿⡄⠀⣴⣶⣿⡄⣿
⣿⡋⠀⠀⠀⠎⢸⣿⡆⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⠗⢘⣿⣟⠛⠿⣼
⣿⣿⠋⢀⡌⢰⣿⡿⢿⡀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣧⢀⣼
⣿⣿⣷⢻⠄⠘⠛⠋⠛⠃⠀⠀⠀⠀⠀⢿⣧⠈⠉⠙⠛⠋⠀⠀⠀⣿⣿⣿⣿⣿
⣿⣿⣧⠀⠈⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠟⠀⠀⠀⠀⢀⢃⠀⠀⢸⣿⣿⣿⣿
⣿⣿⡿⠀⠴⢗⣠⣤⣴⡶⠶⠖⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡸⠀⣿⣿⣿⣿
⣿⣿⣿⡀⢠⣾⣿⠏⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠛⠉⠀⣿⣿⣿⣿
⣿⣿⣿⣧⠈⢹⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿
⣿⣿⣿⣿⡄⠈⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣴⣾⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣦⣄⣀⣀⣀⣀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠀⠀⠀⠙⣿⣿⡟⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠁⠀⠀⠹⣿⠃⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⢐⣿⣿⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⠿⠛⠉⠉⠁⠀⢻⣿⡇⠀⠀⠀⠀⠀⠀⢀⠈⣿⣿⡿⠉⠛⠛⠛⠉⠉
⣿⡿⠋⠁⠀⠀⢀⣀⣠⡴⣸⣿⣇⡄⠀⠀⠀⠀⢀⡿⠄⠙⠛⠀⣀⣠⣤⣤⠄⠀
Ok but what if I WANT to assume the axiom of choice?
Ok well why don't you go CHOOSE a basis for the vector space of continuous functions R -> R 😤
@@SheafificationOfGalready did.
@@SheafificationOfG sure:
Let B be one of the bases for the vector space of continuous functions R→R guaranteed by the axiom of choice. By Zorn's lemma we may (through torturous restructuring into any other arbitrary form of the AoC) select basis B. Thus we now have a basis for the aforementioned space. QED.
@@SheafificationOfGI choose polynomials as a perfectly good Schauder basis 😎
@@ThePiotrekpecet Hamel basis or gtfo
love the video! As a tip for audio quality (because microphones are expensive), it’s a great trick to record the white noise in the room you’re recording in, and put it over any blank spots in the script. That way the audio-to-no-audio transformation isn’t so harsh. Subbed!
Thanks for the tip! I'll consider it for my next video(s)!
If your recording software supports VST plugins you can install Reaper and use ReaFir in subtract mode to remove the background noise. Just let it build the noise profile for few seconds and it's almost gone on all recordings.
@@AKW91 audacity has noise removal built-in
Great video man!!!
That SQL injection tho😂😂😂
Gotta keep the bots away somehow 😉
I don't know how many people you expected to actually laugh out loud at the punchline at 1:18, but I *was* one of them.
Same here 😂
I laughed at the axiom of choice bit
You explained everything super clearly. Even though this is easily the highest level, I've heard anyone go into monads, I actually understood. Can't wait for the next upload!
Geez. I learned both FP+Formalization (under the umbrella term of 'Programming Language') and pure math, and was thinking about all the foundation stuffs from time to time from my enjoyment. You are very strong at explaining the _intuition_ behind it as clear as possible while getting as deep as it can get in understanding. Much thanks and I look forward for future videos!!
Suggestion that you can freely ignore: Is the set X of 'computable' real numbers countable? There is only a countable number of programs, so it should be countable. Now by enumerating X and using the Cantor diagonalization, can't we get contradiction by finding a computable number outside X? (A counterargument gives a resolution of Halting problem) Now how about the set of 'defineable' real numbers? There is only a countable number of math statements. How about we do the Cantor diagnoalization again here?
I'm saying all this without clarity and only handwaiving... what I'd like to see is a crystal clear clarification around those issues if you get what I mean.
Thanks! The angle on Cantor's diagonalisation to prove that the computable numbers are not computably enumerable (despite being countable) is definitely cute! I'll see if it fits with some topics I might want to cover down the road!
I've seen a lot of monad-explainers on youtube, but this is the first one I feel I really understood, so thanks for that! What would you recommand to start learning category theory? Or perhaps to learn more about applications of cat in cs?
(Btw, I AM assuming the axiom of choice, and in fact in every waking moment of my life I am consciously assuming it!)
Thanks so much, I appreciate it (except for the part where you choose the axiom of choice)!
As for category theory recommendations: I've heard that "Category Theory for Programmers" (github.com/hmemcpy/milewski-ctfp-pdf) is good, but I've personally never read it.
I studied category theory purely as a mathematical endeavour, mainly in its intersection with algebraic topology, so I can't say my curated advice would be too valuable to someone on the CS side, though hopefully the book reference is useful.
Accessible and satisfying explanation of Monads. Thank you.
"""Accessible"""
Best debut video ive watched with this few views
Explaining monads in fp as just being a type that allows you to compose an effect when used on any other arbitrary type instantly made perfect sense compared to all the other explanations I've heard over the years when trying to grok it
Thanks a tonne, I'm flattered. So happy to hear found the explanation clear!
The only thing that would make this even more complete would be discussion on monads in philosophy and in physics.
Also I find it ridiculous that mathematicians just went ahead and said to itself, "I know there is 5 times 5, and there is 5 times X, but what if I did 5 times apple?" and just, invented a whole terminology for that.
Preschooler-level creativity - which is creativity of the highest order.
Oh neat, what's a monad in physics? (Not that I really know what a monad in philosophy is, but I came across it while browsing for content...)
@@SheafificationOfG Oh hey, thanks for commenting!
If you want, you could describe a Monad as being a "perfectly unified/most basic thing/concept, often which if the original Thing." Rather important in Greek philosophy. Plus, a lot of religions tend to think of God as a monad.
It would be cool to see how this relates to math, including set theory and ideas of infinity (for example, you can use set theory to prove God cannot make a rock he can't lift, since that would involve making another God, or God being a self-defined thing with no need to have been created, but that's a whole discussion).
I'd say the best advice is just to browse wikipedia on this and absorb whatever you can, and when you see something that looks like it intersects with your fields, dive into it properly.
As for physics, I was thinking in terms of singularities, eg black holes, which arguably are unified point in the universe where the density is arguably infinite. You'll probably find making a vid on that much easier.
@@penand_paper6661 Ah, that description of the philosophical monad is roughly what I gathered from my 10s of browsing (definitely not my wheelhouse).
Do physicists really refer to singularities as monads?
@@SheafificationOfG Truthfully, physics is not my area of expertise. However, I once saw the term used to describe singularities.
I think you'd have a better time looking into the physics, as the math you worked with in the vid might have an application somehow there. (And since physics is basically applied maths.)
This is *hilarious* and also a pretty clear and concise explanation, subbed
this is fantastic, perfect blend of humour and wit
As an undergraduate interested in categorical logic, I'm so glad that I clicked this video, really well done! Love the concise yet accurate language and the funny presentation style, can't wait to see more videos!
Also just a curious question: judging from your username, I would assume you have some background in topos theory? If so, how do you make sense of Beck monadicity theorem and Pare theorem (the latter says that for every elementary topos, the "powerobject" functor is monadic)? I never feel comfortable with them.
Regarding Beck monadicity: if you're willing to accept that a "monad" is a general way of encoding a flavour of "algebraic structure" on objects of a certain category, then Beck's monadicity theorem is a recognition theorem for when you can view objects of one category as "objects of another category with algebraic structure". This perspective also gives a bit of intuition for the conditions on a functor U : C -> D to be monadic:
1. U having a left adjoint establishes that you can use the putative algebraic structure to *generate* an algebra from an "unstructured" object in D (analogous to "formal linear combinations" generated over a set in the video), and it identifies which objects of C are freely-generated.
2. U creating coequalisers of U-split pairs reflects the fact that a general algebra admits a presentation via "generators and relations" (like a free resolution of a ring; in fact, this is a good place to draw intuition).
Regarding Paré's result on the monadicity of the contravariant power-object functor, I think a good starting point for drawing intuition is to look at the category of Sets. Again, if we take "monadicity" of U : C -> D to mean "C is the category of objects of D equipped with a certain kind of algebraic structure", then understanding the monadicity of \Omega : E^op -> E amounts to understanding how to view objects of E^op as objects of E with algebraic structure. For sets, (classically) we have an equivalence of categories between Set^op and the category CABA of "complete atomic Boolean algebras", from which it's apparent what algebraic structure is encoded by the contravariant powerset functor. This gives an impression of what's going on in general (though, you have to let go of LEM, so you don't get "Boolean algebras").
This video gets better everytime you watch it.
I rarely comment on UA-cam. BUT, this video made me to! It’s rare to find such an impeccable mixture of comedy and serious math.
Thank you so much!
Funny and impressive explanation. I did not expect you to get into Kleisli vs Eilenberg-Moore. It's a choice of technical presentation that I think sacrifices intuition, but it's equivalent to the induced T-modules versus *all* T-modules. I'd always felt like the programmers were using monads in a weird way and this helped elucidate that.
I still don't see how that first joke about a monad being a single object endofunctor enriched category actually works though - that's *any* category considered as a singleton subcategory of the category of categories.
Feels like it's a homage to the joke definition of a group as a single-object groupoid but here I don't see the equivalence.
Just like how a monoid is a category with one object, a monoid object in V is equivalent to a V-enriched category with one object.
So, since "a monad is a monoid in the category of endofunctors", it follows that a monad is an endofunctor-enriched category with one object.
But yes, it is a bit of an homage to the group vs groupoid joke :)
Also, a category is not determined by its corresponding singleton subcategory of Cat. For example, both the initial and terminal objects in Cat have equivalent endofunctor categories.
@SheafificationOfG Ah, I see where my sleep deprived brain went wrong - I made the classic newbie mistake of thinking of the V-enrichment in terms of each morphism being an object of V rather than replacing the hom-space itself by an object of V. Now that I've had lunch and a nap it makes a lot more sense.
I am my own functional programming friend, and I also have no idea what a monad is. Though understanding 20% of this video is as close as I've ever been
rare functional programmer who's on good terms with himself
THAT WAS THE BEST WAY TO EXPLAIN MONADS
after learning a bunch of mathematical logic and getting into haskell and lambda caluclus and type theory, this whole thing now makes a lot of sense. (i was an expert c++ programmer, so i'm familier with impure functions or functions that obfuscate their state).
monoid monad endofunctor T Algebra formal R3 vector space
Great video, this was unbelievably interesting! You earned yourself a subscriber.
What is your background?
Thanks!
As for my bg: just a humble abstract homotopy theory enjoyer
You deserve those 1m+ subs, keep going!
Really gunning for that non-free vector space reveal, eh? 😏
tbh I'm friends with monads from both points of view so I just came here for the memes; but the relation FP:Algebra ≈ Kleisli:EM was an unexpected epiphany! 🤯
... then I started wondering what the dual of an epiphany is and ended up realizing I still haven't found the time to play Danganronpa T_T
anyway, subbed 👍
That was masterful. Split your arrow on a double bulls-eye. Subbed.
Monads at 3am, life couldn’t be better
I didn't understand the cat theorist's perspective, but the jokes are incredibly funny
Great vid. Every time you make fun of programmers for using multivalued functions with implicit arguments, Euler sheds a tear.
This was actually very helpful and understandable.
As a mathematician, I felt vindicated by the ending. I can also assure you, every vector space is freely generated. Can you imagine living in a world where some K-vector spaces are neither injective nor projective ? Having a nontrivial cohomological theory for K-vector spaces ?
Have you thought of the ramifications that jumpscare-denying AC can have on poor unsuspecting algebraic geometers just chilling around ?
Kind of irresponsible.
youtube has been desperate for me to watch this video for weeks so here i finally am. cool stuff.
1:36 I wish people did this more often when explaining math concepts
Good luck with your channel! This is great content. Personally, I'd use less distracting images while on such a denser subject (i know the subject matter, but still had to pause a few times or scroll back).
i still dont know what a monad is but thanks for the effort it was a pleasant experience
Best math + meme channel on YT. Subbed.
Well, i guess you could consider the UA-cam algorithm to be a bot. So, that last category fits everyone who didn't specifically look for this video.
Not a bad take...
very intuitive explanation 👍
2:22
Imma steal this joke so I could tell my computer scientist buddies that they're mathematicians.
" they're just monoids in the category of endofunctors" 😛
A monad is a monoid in the category of endofunctors.
A monad is a monoid in the category of endofunctors.
A monad is a monoid in the category of endofunctors.
A monad is a monoid in the category of endofunctors.
A monad is a monoid in the category of endofunctors.
A mo
....................../´¯/)
....................,/¯../
.................../..../
............./´¯/'...'/´¯¯`·¸
........../'/.../..../......./¨¯\
........('(...´...´.... ¯~/'...')
.........\.................'...../
..........''...\.......... _.·´
............\..............(
..............\.............\...
@@SheafificationOfG 🤣🤣🤣
7:10 I had this exact moment with path algebras of quivers... like what does it mean to 'add' two paths together if they are in disjoint parts of the quiver....?
I feel like my brain is getting bigger each time I'm watching this video... Bros is it what we call banger content?
Im from the category of people that accidentally clicked a FP video and the algorithm has been sandblasting my face with FP related vids ever since last week
(Rookie mistake)
What a great explanation, awesome video
I think the disagreement over what a function is is not so much its domain and codomain, but rather that a function in computers describe an algorithm to be run, i.e. a procedure. A mathematical function is not a procedure to run or to be evaluated, it just is. It is a common misconception that expressions like sin(e/pi) do not have an exact value, but indeed it is. sin(e/pi) is exactly sin(e/pi). What is commonly meant is that it isn't a computable or "calculable" number.
But mathematical expressions or functions are not *procedures*, which is usually how more laymen people, applied mathematicians and computer scientists tend to view them.
Is it really common to believe that sin(e/pi) doesn't have an exact value?
It may not have a closed form, but this number is "computable" (in the sense that there is an algorithm for computing sin(e/pi) to whatever desired precision in finite time).
The discrepancy is definitely that mathematics views functions as a unique abstract association of an output (in the codomain) to any input (in the domain), whereas procedural programming views functions as an abstraction for parameterised computation. The point for introducing monads is just that they offer a way of reconciling the latter so that it can be studied as a mathematical (i.e., "pure") function, and remarkably this can be done by having a monad modify the codomain according to the type of effect the procedure has when executed.
However, this is not to say that the discrepancy between functions in maths and CS is a matter of the choice of codomain. Monads are, of course, not the "be-all and end-all" of encoding procedures as (pure) functions: monads are only capable of encoding the "computational effects" of a procedure. It's not necessarily ideal for encoding so-called "computational context" (which affect the behaviour of the procedure)---such things are better suited to comonads.
@@SheafificationOfG And by "an abstraction for parameterised computation" you mean a procedure that eventually produces the desired output. I am arguing that this procedure-based view is a much more fundamental disagreement rather than the domain and codomain.
@@markusklyver6277 I agree with you that the procedural nature of functions in programming is definitely the more fundamental thing, but I'm just confused by what you mean regarding a "disagreement in co/domain"... I don't recall saying something along this line in the video.
I (hopefully) didn't claim that all discrepancies can be resolved by having procedures appeal to co/monads to become pure functions, but the focus of the video was on monads, so naturally the discrepancy between math/cs functions that's important to me in this case is the presence of computational effects (which, of course, fall out of the procedural nature of these functions).
Monads are *not* monoids in the category of endofunctors... rather, if *C* is _any_ 2-category, then a monad is a monoid in the category *C*(A,A) for an object A in *C*.
I am of the category of people that try to understand what Gotfiried Wilhelm Leibniz and Baroch Spinoza have in common, who starts actively sweating, whenever I see a depiction involving more than 3 mathematical signs in a sentence.
Also category 5
But I'm also a postgrad CS student with a minor in maths. So it's at least kinda relevant to me
"If you are a functional programmer, you are interested in the category of sets where the maps from X to Y are the pure functions from X to T(Y)"
Can someone explain what this means? Does this mean that (maps from X to Y) map (by the category) to (the pure functions from X to T(Y))? Or am I misunderstanding categories completely
Yes, arrows X -> Y in the category are given by pure functions X -> T(Y) of sets!
@@SheafificationOfG thank you!
I believe a Monad is a red sword that allows you to see the future
very good video the sweetspot of math and FP
13:27, I'm keeping you to that!
Great video! I feel like this is the closest I've ever gotten to understanding fmap, join, and bind. I'm just… not *quite* there. I'm also unsure what monads can do that generically-typed structs (like std::pair) can't. Finally, the example used to demonstrate fmap glosses over what happens if the division function fails; it feels as though fmap is told "just assume no errors will occur and operate as if the types were X and Y instead of T(X) and T(Y)".
Thanks!
Regarding your comment on generically-typed structs vs monads, I think the misconception is that monads are more of a "design pattern" than a "data structure". There are many ways you can *implement* a monad.
For example, std::optional *is* an implementation of the Maybe monad (where the "new element" is std::nullopt). Of course, you can go your whole life without thinking about std::optional as a monad (or without even using std::optional, really), but the monad perspective can help you navigate your usage of std::optional.
For example, if we use the pure implementation of division (4:33), how do we pass its output to is_pos? C++ will complain if you just pass a std::optional into is_pos, so you need to write a wrapper for is_pos to only deal with the "float part":
if (input.has_value())
{ return is_pos(input); }
else
{ return std::nullopt; }
This wrapper is exactly fmap(is_pos).
In particular, what you say about fmap really is what happens: fmap expresses how pure functions are completely unaware of any computational effects. If the input to fmap(is_pos) were an error (due to division by zero, say), the result of fmap(is_pos) is the same error. In particular, fmap isn't supposed to do anything too deep, and is just there to "correct the input/output types" of a pure function.
@@SheafificationOfG this makes a lot of sense for "programming on rails" monads like maybe, but what does fmap do with the state monad? My immediate guess would be that it executes the pure function then discards the state output, but that implementation removes logic which sounds silly
@Seltyk in general, fmap "passes effects along" through pure functions. If you have a pure function f : X -> Y, then fmap for the state monad transforms this function into a map Funcs(S, X x S) -> Funcs(S, Y x S). In other words, you can imagine the input of fmap(f) being "a value x that depends on state and, when obtained, alters the state", so the output is "the value f(x) that depends on the state and, when obtained, alters the state [where the effect on state is done when finding x before plugging into f]".
If you try to use a pure function f : X -> Y and construct a function fmap(f) of the correct type, this is essentially the only natural way to do it.
I hope this helps!
That was quick, that was clean
7:14
Someone looked into Combinatorial Game Theory
That's easy, a monad is a monoid in the category of endofunctors
5th category; I've forgotten what monads are, so I feel that I need a reminder.
this actually made a lot of sense up until a bit past the 5 minute
Soooooo, T stores operations as strings, and the monad runs eval() on them? No? I didn't get it 😢.
To become closer with the Monad you must reject the earthly (demiurge) I recommend looking into the Pistis Sophia.
perfect introduction
um... does a monad that returns a placeholder value consistent with the expected return value type, on failure, instead of throwing, still qualify as a maybe?
The maybe monad *always* extends a type to have a new element. If your implementation of division returns 0, say, when dividing by zero, then you actually just have a good old-fashioned pure function with no computational effects at all.
@@SheafificationOfG horay, thanks! I'll update my comments to call a certain collection of functions just functions, then. :)
6:55 That's why all the homies use inner product spaces.
I'm here thanks to the algorythm. I switched from math to cs like 2 years ago. I love math more, but it just didn't work out and it was on my part that I didn't bring more into thsi relationship.
I switched from CS back into math for grad school (what I'm trying to say is, math will always love you back).
category 5: I was watching one of your other videos and it mentioned this one (cosets)
Do a video on adjunctions!
Amazing. Make more!!
I actually understand what the fuck a monad is now
Maybe the real monad was the Pythagorean supreme being which forms the unity of all things
"free means no relationships" next to an image of the anime Free
That I know fore sure. A monade is a monoïde in the category on andofunctir
A monad is a monoid in the category of endofunctors 🕺
Dammit, I TOLD you not to say that!
@@SheafificationOfG The funny thing is, I haven't even watched far enough to hear you say that yet since I've been busy, I just came from the followup video to this one and had to say it 🤣. It was purely coincidental and reactionary lmao
I've accepted that I may never understand what a monad is.
This has to be the weirdest faction of gnosticism there is
Wtf is monad? Is it from Monadology by Leibniz?
Okay, but why didn't you discuss the monad of philosophy
6th category, learning maths
can you do what is a gonad next
I now understand monads less than I did before this video
A monoid in the category of endofunctors
Why am I watching this? I already know what a monad is. And a ringad for that matter.
And operads.
Operads are *chef's kiss*
but wtf is a "ringad"? An Ab-enriched monad?
was trying to watch the video, got SQL injected instead
I'm category 3 and my fight is that monads is for functional programmers who are simply looking to cheat and write iterable programming instead.
Also, I love the explanations. Yet I retain the idea that monads are simply a box I put my object in and then leave a note on the box for the next time somebody might want that object.