Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Monad instance of pair on Hackage has no implementation for return?

Tags:

haskell

monads

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?

like image 223
Enlico Avatar asked Dec 30 '22 15:12

Enlico


1 Answers

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.

like image 183
Joseph Sible-Reinstate Monica Avatar answered Feb 23 '23 01:02

Joseph Sible-Reinstate Monica