3 ms·
A monad must have a `return` function that works on an arbitrary datatype. That includes a datatype that is already 'wrapped' in the monad. For example, `return
by nbouscal 14y ago
A monad must have a `return` function that works on an arbitrary datatype. That includes a datatype that is already 'wrapped' in the monad. For example, `return $ Just 5` yielding `Just (Just 5)`. jQuery does not have such a function. The `jQuery` function can 'wrap' strings, but it cannot wrap, for example, other jQuery objects. If you try, you simply get the original jQuery object back. Accordingly jQuery does not satisfy the monad laws, and is therefore not a monad.
- jes5199 14y agoI deny that the return function is required to act on arbitrary data types. In Haskell, is the type [Integer] no longer a monad because it only can contain integers?
- nbouscal 14y agoYes, in Haskell the type [Integer] is not a monad. For a type to be an instance of the Monad type class, it must be of kind * -> * . As [Integer] is of kind * , it cannot possibly be an instance of Monad.
- jes5199 14y agoI didn't mean to suggest that [Integer] was of type Monad, I meant that when you write code in terms of the List monad, that code still works and is still valid and is still "monadic" even when the input to that code is a list of a non-polymorphic type.
- nbouscal 14y agoI really don't follow what you're trying to say here. >>= has signature m a -> (a -> m b) -> m b, so clearly you are working with a concrete type m a. The point is that the concrete type isn't what instantiates the Monad type class, the constructor m is.
- frio 14y agoThe distinction is: return [Integer] will give you [[Integer]] (if you're inside the list Monad). $($("#some-id")) will give you the same result as $("#some-id"), because $ of a $ doesn't nest (or make sense, really). Therefore jQuery doesn't satisfy the Monad laws :).