Commit a741e69a authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺

Provide default implementation of `Monad(return)`

This was dropped last-minute from d94de872
(re #4834) together with the default implementation for `(>>)`
(see 65f887e1 for explanation).

However, the risk of accidental mutually recursive definitions of
`return`/`pure` is rather low as unlike with the `(>>) = (*>)` default,
any cyclic definitions would necessarily wind up being new ones, rather
than changing the semantics for old operations and introducing bottoms.

On the other hand, not having the default method implementation in place
in GHC 7.10 would complicate/delay any future attempt to clean-up the
`Monad`-class.

This finally allows (for `base >= 4.8`) to define a F/A/M instance-chain
with the following minimal definitions (while ignoring that `return` is
still a class-method in `Monad`)

  instance Functor M where
    fmap  = ...

  instance Applicative M where
    pure  = ...
    (<*>) = ...

  instance Monad M where
    (>>=) = ...

Reviewed By: ekmett, austin

Differential Revision: https://phabricator.haskell.org/D647
parent 9bc13c07
......@@ -468,6 +468,7 @@ class Applicative m => Monad m where
-- | Inject a value into the monadic type.
return :: a -> m a
return = pure
-- | Fail with a message. This operation is not part of the
-- mathematical definition of a monad, but is invoked on pattern-match
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment