Transcript from the "Monads Q&A" Lesson

[00:00:00]

>> Kyle Simpson: Any questions about monads? Yes?

>> Speaker 2: You said that the identity here was kind of a cheat. How would you get the value out?

>> Kyle Simpson: You don't really get the value out. You just keep making more monads that do whatever you need them to do with it. It's kind of like how in function calls, you don't, until the very end, do your side effect and cheat.

[00:00:20] So it's like everything is a monad that makes another monad that makes another monad. And then at the very end, you do your side effect and your cheat, right? That's basically why I'm doing it here at the very end, to show you. The line 25 is a violation of the monadic laws.

[00:00:35] But it's also the end of our operation, so it doesn't matter. It's okay if we go ahead and pull it out. Everything else above it is behaving by those laws.

>> Kyle Simpson: And just to make sure we're clear. The reason line 25 is a violation of the monadic law is because .chain has to be called with a monad returning function.

[00:00:56] An identity is not a monad returning function, at least not necessarily a monad returning function. That's why it's a violation of law.

>> Speaker 3: Is the Monad, is that a mathematical thing that you could go study the actual mathematics of it? That-

>> Kyle Simpson: There is absolutely math behind monads, yes.

[00:01:16]

>> Speaker 3: And it's actually called a monad in mathematics? Or was that a name that they made up in programming? Is that name underlined-

>> Kyle Simpson: The question that you're asking is a little interesting because the evolution of the programming and the evolution of the math, at least from my perspective, seem to have been cojoined.

[00:01:39] So I'm not sure that it matters that it was first in math or first in programming. But there is mathematic principles underlying the concept of a monad. So you can't have invented the programming without the math having first been there.

>> Speaker 3: Right, but it's not called a monad in mathematics.

[00:01:59] What the monad is and the mathematics that it's built on, that's not what it's called in mathematics.

>> Kyle Simpson: That's kinda like saying it's not called a functioning method. It is called a function, but it doesn't really matter what it's called. What matters is what it does. So the laws of category theory and all of that that give us a monad, those are valid math.

[00:02:23] And we realize them in programming using some programming language's particular syntax.

>> Speaker 3: Right, what did you just say? What kind of math? You just said the-

>> Kyle Simpson: There's a broader type of math that underlies a lot of functional programming. There's actually more than one, but category theory.

>> Speaker 3: Category theory.

[00:02:42]

>> Kyle Simpson: And I'm way beyond my depth here, right? But category theory is essentially how we describe all of these different kinds of behaviors. And each different thing is some mixture of other different kinds of things. So what category does it fit into?