Commit b4060858 authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Generalise Control.Monad.{sequence_,msum,mapM_,forM_}

This finally takes the gloves off, and performs the first actual
generalization in order to implement #9586. This re-exports the
respective definitions for the 4 combinators defined in Data.Foldable.

This way, importing Data.Foldable and Control.Monad unqualified won't bring
conflicting definitions of those 4 entities into scope anymore.

This change seems to have some minor effect on rule-firing, which
causes some wibble in the test-case T4007

Reviewed By: ekmett, austin

Differential Revision: https://phabricator.haskell.org/D226
parent af22696b
......@@ -76,12 +76,11 @@ module Control.Monad
, (<$!>)
) where
import Data.Foldable ()
import Data.Foldable ( sequence_, msum, mapM_, forM_ )
import Data.Functor ( void )
import Data.Maybe
import GHC.List
import GHC.Base
import GHC.List ( zipWith, unzip, replicate )
-- -----------------------------------------------------------------------------
-- Prelude monad functions
......@@ -94,22 +93,11 @@ sequence ms = foldr k (return []) ms
where
k m m' = do { x <- m; xs <- m'; return (x:xs) }
-- | Evaluate each action in the sequence from left to right,
-- and ignore the results.
sequence_ :: Monad m => [m a] -> m ()
{-# INLINE sequence_ #-}
sequence_ ms = foldr (>>) (return ()) ms
-- | @'mapM' f@ is equivalent to @'sequence' . 'map' f@.
mapM :: Monad m => (a -> m b) -> [a] -> m [b]
{-# INLINE mapM #-}
mapM f as = sequence (map f as)
-- | @'mapM_' f@ is equivalent to @'sequence_' . 'map' f@.
mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
{-# INLINE mapM_ #-}
mapM_ f as = sequence_ (map f as)
-- -----------------------------------------------------------------------------
-- Functions mandated by the Prelude
......@@ -133,17 +121,6 @@ forM :: Monad m => [a] -> (a -> m b) -> m [b]
{-# INLINE forM #-}
forM = flip mapM
-- | 'forM_' is 'mapM_' with its arguments flipped
forM_ :: Monad m => [a] -> (a -> m b) -> m ()
{-# INLINE forM_ #-}
forM_ = flip mapM_
-- | This generalizes the list-based 'concat' function.
msum :: MonadPlus m => [m a] -> m a
{-# INLINE msum #-}
msum = foldr mplus mzero
infixr 1 <=<, >=>
-- | Left-to-right Kleisli composition of monads.
......
Rule fired: unpack
Rule fired: Class op return
Rule fired: Class op >>
Rule fired: Class op return
Rule fired: Class op foldr
Rule fired: Class op >>
Rule fired: Class op return
Rule fired: Class op foldr
Rule fired: Class op >>
Rule fired: Class op return
Rule fired: <=#
Rule fired: tagToEnum#
Rule fired: Class op foldr
Rule fired: fold/build
Rule fired: unpack-list
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