While writing down this answer, mostly to get a better understanding of pairs as monads, I stumbed into this source code on Hackage where I read, in reference to the Monad
instance of (,) a
only this
instance Monoid a => Monad ((,) a) where
(u, a) >>= k = case k a of (v, b) -> (u <> v, b)
where's return
??? I expected to find something like this
return a = (mempty, a)
in addition to the two lines above. Is this definition of return
somehow implied by something else? Or maybe it's defined somewhere else?
In modern versions of Haskell (specifically, base
version 4.8.0.0 and newer, corresponding to GHC version 7.10.1 and newer), the Monad
class has the default implementation return = pure
, so instances of it only need to define >>=
. This was a result of the Functor-Applicative-Monad Proposal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With