
Andrew Wagner wrote:
Here's a clearer description: class Monad m where return :: a -> m a (>>=) :: m a -> (a -> m b) -> m b
Instances of Monad must satisfy the following laws: return a >>= k == k a m >>= return == m m >>= (k >>= h) == (m >>= k) >>= h
Much more clear and concise, don't you think?
Actually, that /is/ clearer for me. Though I still think I'll need the tutorial Colin gave me to gain better intuition and understand the motivations behind monads. That said, I do have questions: 1) Am I right in thinking that any type with two elements ("m a") is always a Monad? (IO String, Maybe Int, etc). 2) When I say "m a >>= f" the >>= just pulls the "a" out of "m a" and passes it to "f". Right? 3) The last two properties are not comparing values but functions. Right? For example, reading the second-last property: (m >>= return) :: a -> m a Where (m >>= return) is defined by (\x -> m x >>= return). Right? And this is why you can write the last property: (k >>= h) :: a -> h a defined by (\x -> k a >>= h) This is what allows us to make (k >>= h) the second argument of ">>=" as in the last property: m >>= (k >>= h) == (m >>= k) >>= h Am I right? Thanks, Daniel.