Is there any reason why Prelude doesn't define a list monad like that? (Note the custom implementation >>.)
instance Monad [] where
m >>= k = concat (map k m)
m >> k = k -- a.k.a. flip const
return x = [x]
fail s = []
I tried to test it against the laws of the monad, but they do not mention >>. The class definition Monadis as follows:
m >> k = m >>= \_ -> k
which in the instance []would translate to this:
concat (map (\_ -> k) m)
which, of course, is not the same flip const- they give is obviously different results, for example [1..5] >> return 1. But it is not clear to me whether this definition by default is the law that the instances must comply with Monad, or is it just a default implementation that satisfies another law that would also satisfy the implementation flip const.
, ( " " ), , >> , , . , , . , flip const ?
: ehird answer , , [] >> k, [], k. , , :
[] >> k = []
_ >> k = k