[commit: ghc] ghc-7.10: Provide default implementation of `Monad(return)` (262f7a8)

git at git.haskell.org git at git.haskell.org
Mon Feb 9 09:07:16 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/262f7a85bb1d40770245b990527eb0bee7c20195/ghc

>---------------------------------------------------------------

commit 262f7a85bb1d40770245b990527eb0bee7c20195
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Sun Feb 8 20:56:58 2015 +0100

    Provide default implementation of `Monad(return)`
    
    This was dropped last-minute from d94de87252d0fe2ae97341d186b03a2fbe136b04
    (re #4834) together with the default implementation for `(>>)`
    (see 65f887e1a0d864526f6a2609a3afc2c151c25e38 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
        (>>=) = ...
    
    (cherry picked from commit a741e69a230eb6d6e3373ad1fbe53c73b5f95077)


>---------------------------------------------------------------

262f7a85bb1d40770245b990527eb0bee7c20195
 libraries/base/GHC/Base.hs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
index 44085a2..7e04ab4 100644
--- a/libraries/base/GHC/Base.hs
+++ b/libraries/base/GHC/Base.hs
@@ -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



More information about the ghc-commits mailing list