A monad, I've been told, is a monoid of X in the category of endofunctors of X, where X is some category.
Maybe is supposedly then a monoid, which means that it is: an object of a category, some operation Maybe x Maybe -> Maybe, and an identity morphism I -> Maybe. Where are they?
What is X in this case? The category of library functions in Haskell?
Also, I don't understand how Maybe even satisfies the Haskell criteria for being a monad which needs a "return" and a "bind". Where are they?
I'm more interested in the internal logic of the concept than its applications.
I found this thread: What is a monad?
It contains:
do user <- getUser 17 addr <- getAddress user getStreetName addrThis
do-block invokes the bind-function for theMaybetype (since the result of the first expression is aMaybe). The bind-function only executes the following operation if the value isJust value, otherwise it just passes theNothingalong.
"bind" is when
Monad a -> (a -> Monad a) -> Monad b
And it seems like the code above first does getUser 17 that is a Maybe String. So it's Int -> Maybe String. Then it passes the Maybe String to getAdress user which is then a
Maybe String -> Maybe String
it should be
String -> Maybe String
So we have:
Maybe String -> (Maybe String -> Maybe String) -> Maybe String
but if it was a "bind", shouldn't it be this?
Maybe String (M a) -> (String (a) -> Maybe String (M a)) -> Maybe [Something Else] (M b)
But even if that was to make sense, what does that have to do with endofunctors?
Maybe StringtogetAddress userwhich is then aMaybe String -> Maybe String" is not correct, and may be the core of your confusion. A corrected statement is "Then, depending on whether theMaybe Stringhas aStringinside or not, it may or may not pass aStringtogetAddress userwhich is then aString -> Maybe String.".