4 ms·
No, I'm sorry, you're wrong. return(return(1))::[[Int]] gives you [[1]]. For something to be a monad, it must be a polymorphic type of kind * -> * . That means
by nbouscal 14y ago
No, I'm sorry, you're wrong. return(return(1))::[[Int]] gives you [[1]]. For something to be a monad, it must be a polymorphic type of kind * -> * . That means it must be a type constructor which takes any type as a parameter. Any type, including a concrete type constructed from the type constructor you are declaring an instance of Monad.
- jes5199 14y agoNo, a monad is not something that implements the Haskell typeclass Monad. A monad is anything that satisfies the monadic laws - and they don't say anything about polymorphism, only associativity and left/right identity. I assert that you can implement a structure that satisfies those laws without having return(return(x)). Can you disprove that? (P.S. you are wronger)
- nbouscal 14y agoIn that particular reply I was talking Haskell specifically; I should have been more clear. You are of course right that being a monad does not mean being an instance of the Haskell type class Monad. It means being a monoid in the category of endofunctors. It does not mean "anything that satisfies ... associativity and left/right identity". You have to specify what operation is associative, which in this case is composition of endofunctors. Associativity and identity on binary operations on sets, for example, gives you a monoid, but not a monad. Monads are more specific, and it is in that specificity that you find the requirement for monads to be "polymorphic": monads are endofunctors, and the monad laws concern the composition of those endofunctors. An endofunctor is a mapping between a category and itself. When we apply this category theory to programming, we talk about a category of types. In Haskell this is the category Hask. This is where the polymorphism requirement comes into play. The monad maps from Hask to itself. That means that it must be able to map over all types, which means polymorphism.
- jes5199 14y agonah, I still don't buy it. Mapping Hask to Hask is an arbitrary choice.
- nbouscal 14y agoThe part that isn't arbitrary is that monads are endofunctors, meaning they must go from a category to itself. That means that the domain and codomain are the same, which means that you must be able to wrap already-wrapped values. There's no way around that.
- jules 14y agoYes, I can disprove. This has nothing to do with Haskell, I'm only going to use the monad laws. The first monad law says: bind f (return a) = f a For all a and f. Therefore, by substituting f = id, and a = return x: bind id (return (return x)) = return x If, as in jQuery, `return (return x) = return x`, then we can simplify to: bind id (return x) = return x Now, applying the first monad law again, we get: x = return x So return must be the identity function. But jQuery's $ is not the identity function. Contradiction. QED.
- jes5199 14y agoI like your answer, but I'm going to refuse to concede that it's correct, out of stubbornness. No wait, I can do better. For some values, $($(x)) is the equivalent to $(x). So, for some values $(y) = y. So for the domain of y where $(y) = y, $() is the identity function, and now it's a monad.
- nbouscal 14y agoNow it's a monad how? What category is it a monad on, and in what way does it satisfy the monad laws? Are you really saying that sometimes $() is return and other times it's id, and presto magico it's a monad?
- jes5199 14y agoLook, if you want to have a discussion with a reasonable person who's going to try to follow your arguments and retort them under the exact same level of rigid discourse that you are using, maybe you should try someone other than me. But yes, presto magico. I am outwitting your narrow-minded mathematics.
- nbouscal 14y agoWell, as long as it's all in good fun :-)