0

A monad is a monoid in the category of endofuctors. Category is a set of two things:

  1. Set of elements
  2. Set of binary operations between these elements.

When we talk about the category endofunctors we also have a set of two things:

  1. Set of endofuctors
  2. Function compositions as binary operations

Function composition is a thing where we apply one functor to an input and then apply another (or the same one) to the result of the previous one. So here is my question: if we don't compose functions does it mean that the whole thing is no longer a monad? Or no compositions is still a set of binary operations, just an empty one?

We can hear them say: a set of integers is a monoid **under addition** (binary operation). So, it makes me think that for a Maybe functor (which I am not even sure it is a functor, since Maybe is an object and a functor is a method (See my previous question)) to be a monad, function composition absolutely must exist there. But unlike the situation with set of integers and a binary operation, with Maybe structure we can achieve something useful without chaining anything at all. It means that if we use a Maybe once, the whole thing is not a monad; but if we use the output of it as an input for another functor call (hence function composition; hence binary operation) then it is a monad! Am I right?

Thanks

1 Answer 1

3

Couple of things here:

  1. It doesn't matter whether we use a thing or not. A monoid is basically a tuple of a set, a null element and a function on that set with specific properties. That's it. It doesn't really matter if we use it, if it makes sense at all, etc. It's just a definition.

  2. Function composition is not really part of the definition of either functor or monad. They just define that specific function must exist. Again, whether you specifically use it or not does not matter, it is still a functor or a monad.

  3. Whether objects can be monads or functors. I think it's fairly easy to establish a homomorphism between object-method and value-function. In other words, I would not get hung up on syntax too much.

Summary: functors and monads are what they are because of how they're defined, not how you use them. You may say that you just need Maybe to be a functor, you don't actually use it to be a monad, i.e. you just need map, but not flatMap. It's still a monad in any practical sense.

5
  • Thank you for your response. It makes sense! However, can you please elaborate more on the 3rd point please? I didn't get that very explanation about the objects being monads instead of functions. Commented Jul 17, 2022 at 19:12
  • 3
    Regarding 3rd point: You're right, that we sometimes call some object functor, sometimes a data structure and we don't even always specify the function to it, etc. In the end it doesn't matter, it only matters whether the requirements of the definition are met. Can you construct the tuple: set, null element, function with the necessary properties? If yes, it's a functor. It doesn't matter what syntax it is in. Does that help? Commented Jul 18, 2022 at 8:11
  • When you write "null element" do you mean the "identity element"? Commented Jul 18, 2022 at 11:52
  • 1
    Yes, I mean identity element. Commented Jul 18, 2022 at 12:30
  • I've took some time to digest what you have said and although your answer does help, I am still not convinced (I disagree) with your second point. Function composition is a binay operation and a monoid must have that binary operation (otherwise it's not a monoid). Since monad is a monoid and function composition is a binary operation, then it is in fact the part of the definition of the monad. I agree with the "if you don't use it it doesn't affect the fact that it is a monad". But I think that function composition must be defined somewhere. Hence, my question remains open. Commented Jul 18, 2022 at 12:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.