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

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
parent 5ed12810
......@@ -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.
......
......@@ -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 (
......
......@@ -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 )
......@@ -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 (
......
......@@ -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
......
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
......@@ -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, [''])
......@@ -7,6 +7,6 @@ T1972.hs:14:3: Warning:
This binding for ‘mapAccumL’ shadows the existing bindings
defined at T1972.hs:16:1
imported from ‘Data.List’ at T1972.hs:7:1-16
(and originally defined in ‘Data.OldList’)
(and originally defined in ‘Data.Traversable’)
T1972.hs:20:10: Warning: Defined but not used: ‘c’
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