diff options
author | Herbert Valerio Riedel <hvr@gnu.org> | 2014-09-21 19:15:46 +0200 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2014-09-21 19:15:59 +0200 |
commit | 1f7f46f94a95ab7fc6f3101da7c02529e1964f24 (patch) | |
tree | 098339660b344ce71a8f7ca289902d10ca82b2b0 /libraries | |
parent | 5ed12810e0972b1e0d408fe1355805746c4614f9 (diff) | |
download | haskell-1f7f46f94a95ab7fc6f3101da7c02529e1964f24.tar.gz |
Generalise Data.List/Control.Monad to Foldable/Traversable
This flips the switch and replaces the entities in
`Data.List`/`Control.Monad` conflicting with
`Data.{Foldable,Traversable}` with re-exports of the more general
versions.
As of this commit, the code below (which is also added as a test-case)
compiles w/o error.
module XPrelude (module X) where
import Control.Monad as X
import Data.Foldable as X
import Data.List as X
import Data.Monoid as X
import Data.Traversable as X
import Prelude as X
This addresses #9568
Reviewed By: ekmett, austin
Differential Revision: https://phabricator.haskell.org/D235
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Control/Monad.hs | 9 | ||||
-rw-r--r-- | libraries/base/Data/Foldable.hs | 6 | ||||
-rw-r--r-- | libraries/base/Data/List.hs | 8 | ||||
-rw-r--r-- | libraries/base/Data/Traversable.hs | 5 | ||||
-rw-r--r-- | libraries/base/changelog.md | 20 | ||||
-rw-r--r-- | libraries/base/tests/T9586.hs | 8 | ||||
-rw-r--r-- | libraries/base/tests/all.T | 1 |
7 files changed, 27 insertions, 30 deletions
diff --git a/libraries/base/Control/Monad.hs b/libraries/base/Control/Monad.hs index c04c4a8f4d..561d40d135 100644 --- a/libraries/base/Control/Monad.hs +++ b/libraries/base/Control/Monad.hs @@ -78,9 +78,9 @@ module Control.Monad import Data.Foldable ( sequence_, msum, mapM_, forM_ ) import Data.Functor ( void ) -import Data.Traversable () +import Data.Traversable ( forM, mapM, sequence ) -import GHC.Base +import GHC.Base hiding ( mapM, sequence ) import GHC.List ( zipWith, unzip, replicate ) -- ----------------------------------------------------------------------------- @@ -101,11 +101,6 @@ filterM p (x:xs) = do ys <- filterM p xs return (if flg then x:ys else ys) --- | 'forM' is 'mapM' with its arguments flipped -forM :: Monad m => [a] -> (a -> m b) -> m [b] -{-# INLINE forM #-} -forM = flip mapM - infixr 1 <=<, >=> -- | Left-to-right Kleisli composition of monads. diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs index 726aa6cb24..2bda8278c7 100644 --- a/libraries/base/Data/Foldable.hs +++ b/libraries/base/Data/Foldable.hs @@ -13,12 +13,6 @@ -- -- Class of data structures that can be folded to a summary value. -- --- Many of these functions generalize "Prelude", "Control.Monad" and --- "Data.List" functions of the same names from lists to any 'Foldable' --- functor. To avoid ambiguity, either import those modules hiding --- these names or qualify uses of these function names with an alias --- for this module. --- ----------------------------------------------------------------------------- module Data.Foldable ( diff --git a/libraries/base/Data/List.hs b/libraries/base/Data/List.hs index e742cac97b..795baec6af 100644 --- a/libraries/base/Data/List.hs +++ b/libraries/base/Data/List.hs @@ -208,9 +208,9 @@ module Data.List ) where import Data.Foldable -import Data.Traversable () +import Data.Traversable import Data.OldList hiding ( all, and, any, concat, concatMap, elem, find, - foldl, foldl1, foldl', foldr, foldr1, maximum, - maximumBy, minimum, minimumBy, notElem, or, - product, sum ) + foldl, foldl1, foldl', foldr, foldr1, mapAccumL, + mapAccumR, maximum, maximumBy, minimum, minimumBy, + notElem, or, product, sum ) diff --git a/libraries/base/Data/Traversable.hs b/libraries/base/Data/Traversable.hs index d050aeaf4d..eb5123dde6 100644 --- a/libraries/base/Data/Traversable.hs +++ b/libraries/base/Data/Traversable.hs @@ -31,11 +31,6 @@ -- in /Mathematically-Structured Functional Programming/, 2012, online at -- <http://arxiv.org/pdf/1202.2919>. -- --- Note that the functions 'mapM' and 'sequence' generalize "Prelude" --- functions of the same names from lists to any 'Traversable' functor. --- To avoid ambiguity, either import the "Prelude" hiding these names --- or qualify uses of these function names with an alias for this module. --- ----------------------------------------------------------------------------- module Data.Traversable ( diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index d7e1133263..0d9589847a 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -38,22 +38,26 @@ * Replace the `Data.List`-exported functions ``` - all, and, any, concat, concatMap, elem, find, product, sum + all, and, any, concat, concatMap, elem, find, product, sum, + mapAccumL, mapAccumR ``` - by re-exports of their generalised `Data.Foldable` counterparts. - In other words, unqualified imports of `Data.List` and - `Data.Foldable` no longer lead to conflicting definitions. (#9586) + by re-exports of their generalised `Data.Foldable`/`Data.Traversable` + counterparts. In other words, unqualified imports of `Data.List` + and `Data.Foldable`/`Data.Traversable` no longer lead to conflicting + definitions. (#9586) * Replace the `Control.Monad`-exported functions ``` - sequence_, msum, mapM_, forM_ + sequence_, msum, mapM_, forM_, + forM, mapM, sequence ``` - by re-exports of their generalised `Data.Foldable` counterparts. - In other words, unqualified imports of `Control.Monad` and - `Data.Foldable` no longer lead to conflicting definitions. (#9586) + by re-exports of their generalised `Data.Foldable`/`Data.Traversable` + counterparts. In other words, unqualified imports of `Control.Monad` + and `Data.Foldable`/`Data.Traversable` no longer lead to conflicting + definitions. (#9586) * New module `Data.OldList` containing only list-specialised versions of the functions from `Data.List` (in other words, `Data.OldList` corresponds diff --git a/libraries/base/tests/T9586.hs b/libraries/base/tests/T9586.hs new file mode 100644 index 0000000000..8310b99bf4 --- /dev/null +++ b/libraries/base/tests/T9586.hs @@ -0,0 +1,8 @@ +module XPrelude (module X) where + +import Control.Monad as X +import Data.Foldable as X +import Data.List as X +import Data.Monoid as X +import Data.Traversable as X +import Prelude as X diff --git a/libraries/base/tests/all.T b/libraries/base/tests/all.T index 5fe862f449..6520b21312 100644 --- a/libraries/base/tests/all.T +++ b/libraries/base/tests/all.T @@ -170,3 +170,4 @@ test('T8766', test('T9111', normal, compile, ['']) test('T9395', normal, compile_and_run, ['']) test('T9532', normal, compile_and_run, ['']) +test('T9586', normal, compile, ['']) |