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

Export `Monoid(..)`/`Foldable(..)`/`Traversable(..)` from Prelude

This finally exposes also the methods of these 3 classes in the Prelude
in order to allow to define basic class instances w/o needing imports.

This almost completes the primary goal of #9586

NOTE: `fold`, `foldl'`, `foldr'`, and `toList` are not exposed yet,
      as they require upstream fixes for at least `containers` and
      `bytestring`, and are not required for defining basic instances.

Reviewed By: ekmett, austin

Differential Revision: https://phabricator.haskell.org/D236
parent 1f7f46f9
...@@ -46,7 +46,9 @@ import FastString ...@@ -46,7 +46,9 @@ import FastString
import Control.Monad import Control.Monad
import Data.Int import Data.Int
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse) import Data.Traversable (traverse)
#endif
import Data.Word import Data.Word
\end{code} \end{code}
......
...@@ -65,7 +65,9 @@ import Data.Array.Base ...@@ -65,7 +65,9 @@ import Data.Array.Base
import Data.Ix import Data.Ix
import Data.List import Data.List
import qualified Data.Sequence as Seq import qualified Data.Sequence as Seq
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid (mappend) import Data.Monoid (mappend)
#endif
import Data.Sequence (viewl, ViewL(..)) import Data.Sequence (viewl, ViewL(..))
import Foreign.Safe import Foreign.Safe
import System.IO.Unsafe import System.IO.Unsafe
......
...@@ -41,10 +41,10 @@ import BooleanFormula (BooleanFormula) ...@@ -41,10 +41,10 @@ import BooleanFormula (BooleanFormula)
import Data.Data hiding ( Fixity ) import Data.Data hiding ( Fixity )
import Data.List import Data.List
import Data.Ord import Data.Ord
#if __GLASGOW_HASKELL__ < 709
import Data.Foldable ( Foldable(..) ) import Data.Foldable ( Foldable(..) )
import Data.Traversable ( Traversable(..) ) import Data.Traversable ( Traversable(..) )
import Data.Monoid ( mappend ) import Data.Monoid ( mappend )
#if __GLASGOW_HASKELL__ < 709
import Control.Applicative hiding (empty) import Control.Applicative hiding (empty)
#else #else
import Control.Applicative ((<$>)) import Control.Applicative ((<$>))
......
...@@ -72,7 +72,9 @@ import FastString ...@@ -72,7 +72,9 @@ import FastString
import Control.Monad import Control.Monad
import qualified Data.Map as Map import qualified Data.Map as Map
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable ( traverse ) import Data.Traversable ( traverse )
#endif
\end{code} \end{code}
This module takes This module takes
......
...@@ -73,7 +73,9 @@ import qualified System.FilePath.Posix as FilePath.Posix ...@@ -73,7 +73,9 @@ import qualified System.FilePath.Posix as FilePath.Posix
import Control.Monad import Control.Monad
import Data.List as List import Data.List as List
import Data.Map (Map) import Data.Map (Map)
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid hiding ((<>)) import Data.Monoid hiding ((<>))
#endif
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified FiniteMap as Map import qualified FiniteMap as Map
import qualified Data.Set as Set import qualified Data.Set as Set
......
...@@ -9,6 +9,7 @@ type-synonym declarations; those cannot be done at this stage because ...@@ -9,6 +9,7 @@ type-synonym declarations; those cannot be done at this stage because
they may be affected by renaming (which isn't fully worked out yet). they may be affected by renaming (which isn't fully worked out yet).
\begin{code} \begin{code}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-tabs #-} {-# OPTIONS_GHC -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge. -- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and -- While working on this module you are encouraged to remove it and
...@@ -55,7 +56,9 @@ import FastString ...@@ -55,7 +56,9 @@ import FastString
import Data.List ( partition, sort ) import Data.List ( partition, sort )
import Maybes ( orElse ) import Maybes ( orElse )
import Control.Monad import Control.Monad
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable ( traverse ) import Data.Traversable ( traverse )
#endif
\end{code} \end{code}
-- ToDo: Put the annotations into the monad, so that they arrive in the proper -- ToDo: Put the annotations into the monad, so that they arrive in the proper
......
...@@ -48,7 +48,9 @@ import Util ( mapSnd ) ...@@ -48,7 +48,9 @@ import Util ( mapSnd )
import Control.Monad import Control.Monad
import Data.List( partition, sortBy ) import Data.List( partition, sortBy )
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse) import Data.Traversable (traverse)
#endif
import Maybes( orElse, mapMaybe ) import Maybes( orElse, mapMaybe )
\end{code} \end{code}
......
...@@ -50,7 +50,9 @@ import Util ...@@ -50,7 +50,9 @@ import Util
import Bag import Bag
import Pair import Pair
import Control.Applicative import Control.Applicative
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse, sequenceA) import Data.Traversable (traverse, sequenceA)
#endif
import qualified Data.Data as Data import qualified Data.Data as Data
import Outputable import Outputable
import FastString import FastString
......
...@@ -58,7 +58,9 @@ import Bag ...@@ -58,7 +58,9 @@ import Bag
import FastString import FastString
import Outputable import Outputable
import Util import Util
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable ( traverse ) import Data.Traversable ( traverse )
#endif
\end{code} \end{code}
%************************************************************************ %************************************************************************
......
...@@ -30,7 +30,9 @@ import BasicTypes ...@@ -30,7 +30,9 @@ import BasicTypes
import TcSimplify import TcSimplify
import TcType import TcType
import VarSet import VarSet
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid import Data.Monoid
#endif
import Bag import Bag
import TcEvidence import TcEvidence
import BuildTyCl import BuildTyCl
......
...@@ -102,7 +102,9 @@ import Pair ...@@ -102,7 +102,9 @@ import Pair
import SrcLoc import SrcLoc
import PrelNames ( funTyConKey, eqPrimTyConKey, eqReprPrimTyConKey ) import PrelNames ( funTyConKey, eqPrimTyConKey, eqReprPrimTyConKey )
import Control.Applicative import Control.Applicative
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse, sequenceA) import Data.Traversable (traverse, sequenceA)
#endif
import FastString import FastString
import ListSetOps import ListSetOps
......
...@@ -10,10 +10,12 @@ module Pair ( Pair(..), unPair, toPair, swap ) where ...@@ -10,10 +10,12 @@ module Pair ( Pair(..), unPair, toPair, swap ) where
#include "HsVersions.h" #include "HsVersions.h"
import Outputable import Outputable
import Data.Monoid
import Control.Applicative import Control.Applicative
#if __GLASGOW_HASKELL__ < 709
import Data.Foldable import Data.Foldable
import Data.Monoid
import Data.Traversable import Data.Traversable
#endif
data Pair a = Pair { pFst :: a, pSnd :: a } data Pair a = Pair { pFst :: a, pSnd :: a }
-- Note that Pair is a *unary* type constructor -- Note that Pair is a *unary* type constructor
...@@ -46,4 +48,4 @@ toPair (x,y) = Pair x y ...@@ -46,4 +48,4 @@ toPair (x,y) = Pair x y
swap :: Pair a -> Pair a swap :: Pair a -> Pair a
swap (Pair x y) = Pair y x swap (Pair x y) = Pair y x
\end{code} \end{code}
\ No newline at end of file
...@@ -20,7 +20,10 @@ and ``addToUFM\_C'' and ``Data.IntMap.insertWith'' differ in the order ...@@ -20,7 +20,10 @@ and ``addToUFM\_C'' and ``Data.IntMap.insertWith'' differ in the order
of arguments of combining function. of arguments of combining function.
\begin{code} \begin{code}
{-# LANGUAGE DeriveTraversable, DeriveDataTypeable, GeneralizedNewtypeDeriving #-} {-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wall #-} {-# OPTIONS_GHC -Wall #-}
module UniqFM ( module UniqFM (
...@@ -76,7 +79,9 @@ import qualified Data.Foldable as Foldable ...@@ -76,7 +79,9 @@ import qualified Data.Foldable as Foldable
import qualified Data.Traversable as Traversable import qualified Data.Traversable as Traversable
import Data.Typeable import Data.Typeable
import Data.Data import Data.Data
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid import Data.Monoid
#endif
\end{code} \end{code}
%************************************************************************ %************************************************************************
......
...@@ -66,14 +66,32 @@ module Prelude ( ...@@ -66,14 +66,32 @@ module Prelude (
subtract, even, odd, gcd, lcm, (^), (^^), subtract, even, odd, gcd, lcm, (^), (^^),
fromIntegral, realToFrac, fromIntegral, realToFrac,
-- ** Monoids
Monoid(mempty, mappend, mconcat),
-- ** Monads and functors -- ** Monads and functors
Functor(fmap), Functor(fmap),
Applicative(pure, (<*>), (*>), (<*)), Applicative(pure, (<*>), (*>), (<*)),
Monad((>>=), (>>), return, fail), Monad((>>=), (>>), return, fail),
mapM, mapM_, sequence, sequence_, (=<<), mapM_, sequence_, (=<<),
-- ** Traversals and Foldables -- ** Folds and traversals
Foldable, Traversable, Foldable(elem, -- :: (Foldable t, Eq a) => a -> t a -> Bool
-- fold, -- :: Monoid m => t m -> m
foldMap, -- :: Monoid m => (a -> m) -> t a -> m
foldr, -- :: (a -> b -> b) -> b -> t a -> b
-- foldr', -- :: (a -> b -> b) -> b -> t a -> b
foldl, -- :: (b -> a -> b) -> b -> t a -> b
-- foldl', -- :: (b -> a -> b) -> b -> t a -> b
foldr1, -- :: (a -> a -> a) -> t a -> a
foldl1, -- :: (a -> a -> a) -> t a -> a
maximum, -- :: (Foldable t, Ord a) => t a -> a
minimum, -- :: (Foldable t, Ord a) => t a -> a
product, -- :: (Foldable t, Num a) => t a -> a
sum), -- :: Num a => t a -> a
-- toList) -- :: Foldable t => t a -> [a]
Traversable(traverse, sequenceA, mapM, sequence),
-- ** Miscellaneous functions -- ** Miscellaneous functions
id, const, (.), flip, ($), until, id, const, (.), flip, ($), until,
...@@ -84,13 +102,9 @@ module Prelude ( ...@@ -84,13 +102,9 @@ module Prelude (
map, (++), filter, map, (++), filter,
head, last, tail, init, null, length, (!!), head, last, tail, init, null, length, (!!),
reverse, reverse,
-- ** Reducing lists (folds)
foldl, foldl1, foldr, foldr1,
-- *** Special folds -- *** Special folds
and, or, any, all, and, or, any, all,
sum, product,
concat, concatMap, concat, concatMap,
maximum, minimum,
-- ** Building lists -- ** Building lists
-- *** Scans -- *** Scans
scanl, scanl1, scanr, scanr1, scanl, scanl1, scanr, scanr1,
...@@ -99,7 +113,7 @@ module Prelude ( ...@@ -99,7 +113,7 @@ module Prelude (
-- ** Sublists -- ** Sublists
take, drop, splitAt, takeWhile, dropWhile, span, break, take, drop, splitAt, takeWhile, dropWhile, span, break,
-- ** Searching lists -- ** Searching lists
elem, notElem, lookup, notElem, lookup,
-- ** Zipping and unzipping lists -- ** Zipping and unzipping lists
zip, zip3, zipWith, zipWith3, unzip, unzip3, zip, zip3, zipWith, zipWith3, unzip, unzip3,
-- ** Functions on strings -- ** Functions on strings
...@@ -143,9 +157,9 @@ import System.IO ...@@ -143,9 +157,9 @@ import System.IO
import System.IO.Error import System.IO.Error
import Data.List import Data.List
import Data.Either import Data.Either
import Data.Foldable ( Foldable ) import Data.Foldable ( Foldable(..) )
import Data.Maybe import Data.Maybe
import Data.Traversable ( Traversable ) import Data.Traversable ( Traversable(..) )
import Data.Tuple import Data.Tuple
import GHC.Base hiding ( foldr, mapM, sequence ) import GHC.Base hiding ( foldr, mapM, sequence )
......
...@@ -29,6 +29,13 @@ ...@@ -29,6 +29,13 @@
* Add `Data.List.uncons` list destructor (#9550) * Add `Data.List.uncons` list destructor (#9550)
* Export `Monoid(..)` from `Prelude`
* Export `Foldable(..)` from `Prelude`
(hiding `fold`, `foldl'`, `foldr'`, and `toList`)
* Export `Traversable(..)` from `Prelude`
* Set fixity for `Data.Foldable.{elem,notElem}` to match the * Set fixity for `Data.Foldable.{elem,notElem}` to match the
conventional one set for `Data.List.{elem,notElem}` (#9610) conventional one set for `Data.List.{elem,notElem}` (#9610)
......
...@@ -132,9 +132,15 @@ libraries/binary_dist-install_EXTRA_HC_OPTS += -Wwarn ...@@ -132,9 +132,15 @@ libraries/binary_dist-install_EXTRA_HC_OPTS += -Wwarn
# temporarily turn off -Werror for mtl # temporarily turn off -Werror for mtl
libraries/mtl_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/mtl_dist-install_EXTRA_HC_OPTS += -Wwarn
# temporarily turn off unused-imports warnings for pretty
libraries/pretty_dist-install_EXTRA_HC_OPTS += -fno-warn-unused-imports
# primitive has a warning about deprecated use of GHC.IOBase # primitive has a warning about deprecated use of GHC.IOBase
libraries/primitive_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/primitive_dist-install_EXTRA_HC_OPTS += -Wwarn
# temporarily turn off unused-imports warnings for terminfo
libraries/terminfo_dist-install_EXTRA_HC_OPTS += -fno-warn-unused-imports
# temporarily turn off -Werror for transformers # temporarily turn off -Werror for transformers
libraries/transformers_dist-boot_EXTRA_HC_OPTS += -Wwarn libraries/transformers_dist-boot_EXTRA_HC_OPTS += -Wwarn
libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wwarn
...@@ -142,6 +148,9 @@ libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wwarn ...@@ -142,6 +148,9 @@ libraries/transformers_dist-install_EXTRA_HC_OPTS += -Wwarn
# vector has some unused match warnings # vector has some unused match warnings
libraries/vector_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/vector_dist-install_EXTRA_HC_OPTS += -Wwarn
# temporarily turn off unused-imports warnings for xhtml
libraries/xhtml_dist-install_EXTRA_HC_OPTS += -fno-warn-unused-imports
libraries/dph/dph-base_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/dph/dph-base_dist-install_EXTRA_HC_OPTS += -Wwarn
libraries/dph/dph-prim-interface_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/dph/dph-prim-interface_dist-install_EXTRA_HC_OPTS += -Wwarn
libraries/dph/dph-prim-seq_dist-install_EXTRA_HC_OPTS += -Wwarn libraries/dph/dph-prim-seq_dist-install_EXTRA_HC_OPTS += -Wwarn
......
import Control.Monad.Fix import Control.Monad.Fix
import Data.IORef import Data.IORef
import Prelude hiding (traverse)
data N a = N (IORef Bool, N a, a, N a) data N a = N (IORef Bool, N a, a, N a)
...@@ -34,4 +35,4 @@ l2dll' :: N a -> [a] -> IO (N a, N a) ...@@ -34,4 +35,4 @@ l2dll' :: N a -> [a] -> IO (N a, N a)
l2dll' p [] = return (p, p) l2dll' p [] = return (p, p)
l2dll' p (x:xs) = mdo c <- newNode p x f l2dll' p (x:xs) = mdo c <- newNode p x f
(f, l) <- l2dll' c xs (f, l) <- l2dll' c xs
return (c, l) return (c, l)
\ No newline at end of file
Stopped at ../mdo.hs:(29,1)-(31,27) Stopped at ../mdo.hs:(30,1)-(32,27)
_result :: IO (N a) = _ _result :: IO (N a) = _
Stopped at ../mdo.hs:(29,16)-(31,27) Stopped at ../mdo.hs:(30,16)-(32,27)
_result :: IO (N Char) = _ _result :: IO (N Char) = _
x :: Char = 'h' x :: Char = 'h'
xs :: [Char] = _ xs :: [Char] = _
Stopped at ../mdo.hs:29:30-42 Stopped at ../mdo.hs:30:30-42
_result :: IO (N Char) = _ _result :: IO (N Char) = _
f :: N Char = _ f :: N Char = _
l :: N Char = _ l :: N Char = _
x :: Char = 'h' x :: Char = 'h'
Stopped at ../mdo.hs:(7,1)-(8,42) Stopped at ../mdo.hs:(8,1)-(9,42)
_result :: IO (N a) = _ _result :: IO (N a) = _
Breakpoint 0 activated at ../mdo.hs:13:16-30 Breakpoint 0 activated at ../mdo.hs:13:16-30
Breakpoint 1 activated at ../mdo.hs:12:16-30 Breakpoint 1 activated at ../mdo.hs:12:16-30
Breakpoint 2 activated at ../mdo.hs:11:16-30 Breakpoint 2 activated at ../mdo.hs:11:16-30
Breakpoint 3 activated at ../mdo.hs:14:10-18 Breakpoint 3 activated at ../mdo.hs:14:16-30
...@@ -25,6 +25,7 @@ instance Eq () -- Defined in ‘GHC.Classes’ ...@@ -25,6 +25,7 @@ instance Eq () -- Defined in ‘GHC.Classes’
instance Ord () -- Defined in ‘GHC.Classes’ instance Ord () -- Defined in ‘GHC.Classes’
instance Read () -- Defined in ‘GHC.Read’ instance Read () -- Defined in ‘GHC.Read’
instance Show () -- Defined in ‘GHC.Show’ instance Show () -- Defined in ‘GHC.Show’
instance Monoid () -- Defined in ‘GHC.Base’
type instance D () () = Bool -- Defined at T4175.hs:22:5 type instance D () () = Bool -- Defined at T4175.hs:22:5
type instance D Int () = String -- Defined at T4175.hs:19:5 type instance D Int () = String -- Defined at T4175.hs:19:5
data instance B () = MkB -- Defined at T4175.hs:13:15 data instance B () = MkB -- Defined at T4175.hs:13:15
...@@ -38,6 +39,7 @@ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’ ...@@ -38,6 +39,7 @@ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
instance Applicative Maybe -- Defined in ‘GHC.Base’ instance Applicative Maybe -- Defined in ‘GHC.Base’
instance Foldable Maybe -- Defined in ‘Data.Foldable’ instance Foldable Maybe -- Defined in ‘Data.Foldable’
instance Traversable Maybe -- Defined in ‘Data.Traversable’ instance Traversable Maybe -- Defined in ‘Data.Traversable’
instance Monoid a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
type instance A (Maybe a) a = a -- Defined at T4175.hs:9:1 type instance A (Maybe a) a = a -- Defined at T4175.hs:9:1
data Int = I# Int# -- Defined in ‘GHC.Types’ data Int = I# Int# -- Defined in ‘GHC.Types’
instance C Int -- Defined at T4175.hs:18:10 instance C Int -- Defined at T4175.hs:18:10
......
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