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

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
import Control.Monad
import Data.Int
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse)
#endif
import Data.Word
\end{code}
......
......@@ -65,7 +65,9 @@ import Data.Array.Base
import Data.Ix
import Data.List
import qualified Data.Sequence as Seq
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid (mappend)
#endif
import Data.Sequence (viewl, ViewL(..))
import Foreign.Safe
import System.IO.Unsafe
......
......@@ -41,10 +41,10 @@ import BooleanFormula (BooleanFormula)
import Data.Data hiding ( Fixity )
import Data.List
import Data.Ord
#if __GLASGOW_HASKELL__ < 709
import Data.Foldable ( Foldable(..) )
import Data.Traversable ( Traversable(..) )
import Data.Monoid ( mappend )
#if __GLASGOW_HASKELL__ < 709
import Control.Applicative hiding (empty)
#else
import Control.Applicative ((<$>))
......
......@@ -72,7 +72,9 @@ import FastString
import Control.Monad
import qualified Data.Map as Map
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable ( traverse )
#endif
\end{code}
This module takes
......
......@@ -73,7 +73,9 @@ import qualified System.FilePath.Posix as FilePath.Posix
import Control.Monad
import Data.List as List
import Data.Map (Map)
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid hiding ((<>))
#endif
import qualified Data.Map as Map
import qualified FiniteMap as Map
import qualified Data.Set as Set
......
......@@ -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).
\begin{code}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
......@@ -55,7 +56,9 @@ import FastString
import Data.List ( partition, sort )
import Maybes ( orElse )
import Control.Monad
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable ( traverse )
#endif
\end{code}
-- ToDo: Put the annotations into the monad, so that they arrive in the proper
......
......@@ -48,7 +48,9 @@ import Util ( mapSnd )
import Control.Monad
import Data.List( partition, sortBy )
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse)
#endif
import Maybes( orElse, mapMaybe )
\end{code}
......
......@@ -50,7 +50,9 @@ import Util
import Bag
import Pair
import Control.Applicative
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse, sequenceA)
#endif
import qualified Data.Data as Data
import Outputable
import FastString
......
......@@ -58,7 +58,9 @@ import Bag
import FastString
import Outputable
import Util
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable ( traverse )
#endif
\end{code}
%************************************************************************
......
......@@ -30,7 +30,9 @@ import BasicTypes
import TcSimplify
import TcType
import VarSet
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid
#endif
import Bag
import TcEvidence
import BuildTyCl
......
......@@ -102,7 +102,9 @@ import Pair
import SrcLoc
import PrelNames ( funTyConKey, eqPrimTyConKey, eqReprPrimTyConKey )
import Control.Applicative
#if __GLASGOW_HASKELL__ < 709
import Data.Traversable (traverse, sequenceA)
#endif
import FastString
import ListSetOps
......
......@@ -10,10 +10,12 @@ module Pair ( Pair(..), unPair, toPair, swap ) where
#include "HsVersions.h"
import Outputable
import Data.Monoid
import Control.Applicative
#if __GLASGOW_HASKELL__ < 709
import Data.Foldable
import Data.Monoid
import Data.Traversable
#endif
data Pair a = Pair { pFst :: a, pSnd :: a }
-- Note that Pair is a *unary* type constructor
......@@ -46,4 +48,4 @@ toPair (x,y) = Pair x y
swap :: Pair a -> Pair a
swap (Pair x y) = Pair y x
\end{code}
\ No newline at end of file
\end{code}
......@@ -20,7 +20,10 @@ and ``addToUFM\_C'' and ``Data.IntMap.insertWith'' differ in the order
of arguments of combining function.
\begin{code}
{-# LANGUAGE DeriveTraversable, DeriveDataTypeable, GeneralizedNewtypeDeriving #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wall #-}
module UniqFM (
......@@ -76,7 +79,9 @@ import qualified Data.Foldable as Foldable
import qualified Data.Traversable as Traversable
import Data.Typeable
import Data.Data
#if __GLASGOW_HASKELL__ < 709
import Data.Monoid
#endif
\end{code}
%************************************************************************
......
......@@ -66,14 +66,32 @@ module Prelude (
subtract, even, odd, gcd, lcm, (^), (^^),
fromIntegral, realToFrac,
-- ** Monoids
Monoid(mempty, mappend, mconcat),
-- ** Monads and functors
Functor(fmap),
Applicative(pure, (<*>), (*>), (<*)),
Monad((>>=), (>>), return, fail),
mapM, mapM_, sequence, sequence_, (=<<),
-- ** Traversals and Foldables
Foldable, Traversable,
mapM_, sequence_, (=<<),
-- ** Folds and traversals
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
id, const, (.), flip, ($), until,
......@@ -84,13 +102,9 @@ module Prelude (
map, (++), filter,
head, last, tail, init, null, length, (!!),
reverse,
-- ** Reducing lists (folds)
foldl, foldl1, foldr, foldr1,
-- *** Special folds
and, or, any, all,
sum, product,
concat, concatMap,
maximum, minimum,
-- ** Building lists
-- *** Scans
scanl, scanl1, scanr, scanr1,
......@@ -99,7 +113,7 @@ module Prelude (
-- ** Sublists
take, drop, splitAt, takeWhile, dropWhile, span, break,
-- ** Searching lists
elem, notElem, lookup,
notElem, lookup,
-- ** Zipping and unzipping lists
zip, zip3, zipWith, zipWith3, unzip, unzip3,
-- ** Functions on strings
......@@ -143,9 +157,9 @@ import System.IO
import System.IO.Error
import Data.List
import Data.Either
import Data.Foldable ( Foldable )
import Data.Foldable ( Foldable(..) )
import Data.Maybe
import Data.Traversable ( Traversable )
import Data.Traversable ( Traversable(..) )
import Data.Tuple
import GHC.Base hiding ( foldr, mapM, sequence )
......
......@@ -29,6 +29,13 @@
* 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
conventional one set for `Data.List.{elem,notElem}` (#9610)
......
......@@ -132,9 +132,15 @@ libraries/binary_dist-install_EXTRA_HC_OPTS += -Wwarn
# temporarily turn off -Werror for mtl
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
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
libraries/transformers_dist-boot_EXTRA_HC_OPTS += -Wwarn
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
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-prim-interface_dist-install_EXTRA_HC_OPTS += -Wwarn
libraries/dph/dph-prim-seq_dist-install_EXTRA_HC_OPTS += -Wwarn
......
import Control.Monad.Fix
import Data.IORef
import Prelude hiding (traverse)
data N a = N (IORef Bool, N a, a, N a)
......@@ -34,4 +35,4 @@ l2dll' :: N a -> [a] -> IO (N a, N a)
l2dll' p [] = return (p, p)
l2dll' p (x:xs) = mdo c <- newNode p x f
(f, l) <- l2dll' c xs
return (c, l)
\ No newline at end of file
return (c, l)
Stopped at ../mdo.hs:(29,1)-(31,27)
Stopped at ../mdo.hs:(30,1)-(32,27)
_result :: IO (N a) = _
Stopped at ../mdo.hs:(29,16)-(31,27)
Stopped at ../mdo.hs:(30,16)-(32,27)
_result :: IO (N Char) = _
x :: Char = 'h'
xs :: [Char] = _
Stopped at ../mdo.hs:29:30-42
Stopped at ../mdo.hs:30:30-42
_result :: IO (N Char) = _
f :: N Char = _
l :: N Char = _
x :: Char = 'h'
Stopped at ../mdo.hs:(7,1)-(8,42)
Stopped at ../mdo.hs:(8,1)-(9,42)
_result :: IO (N a) = _
Breakpoint 0 activated at ../mdo.hs:13:16-30
Breakpoint 1 activated at ../mdo.hs:12: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’
instance Ord () -- Defined in ‘GHC.Classes’
instance Read () -- Defined in ‘GHC.Read’
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 Int () = String -- Defined at T4175.hs:19:5
data instance B () = MkB -- Defined at T4175.hs:13:15
......@@ -38,6 +39,7 @@ instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
instance Applicative Maybe -- Defined in ‘GHC.Base’
instance Foldable Maybe -- Defined in ‘Data.Foldable’
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
data Int = I# Int# -- Defined in ‘GHC.Types’
instance C Int -- Defined at T4175.hs:18:10
......
......@@ -5,6 +5,7 @@ instance Eq () -- Defined in ‘GHC.Classes’
instance Ord () -- Defined in ‘GHC.Classes’
instance Read () -- Defined in ‘GHC.Read’
instance Show () -- Defined in ‘GHC.Show’
instance Monoid () -- Defined in ‘GHC.Base’
data (##) = (##) -- Defined in ‘GHC.Prim’
() :: ()
(##) :: (# #)
......@@ -18,10 +19,11 @@ instance Functor ((,) a) -- Defined in ‘GHC.Base’
instance (Ord a, Ord b) => Ord (a, b) -- Defined in ‘GHC.Classes’
instance (Read a, Read b) => Read (a, b) -- Defined in ‘GHC.Read’
instance (Show a, Show b) => Show (a, b) -- Defined in ‘GHC.Show’
instance GHC.Base.Monoid a => Applicative ((,) a)
-- Defined in ‘GHC.Base’
instance Monoid a => Applicative ((,) a) -- Defined in ‘GHC.Base’
instance Foldable ((,) a) -- Defined in ‘Data.Foldable’
instance Traversable ((,) a) -- Defined in ‘Data.Traversable’
instance (Monoid a, Monoid b) => Monoid (a, b)
-- Defined in ‘GHC.Base’
data (#,#) (a :: OpenKind) (b :: OpenKind) = (#,#) a b
-- Defined in ‘GHC.Prim’
(,) :: a -> b -> (a, b)
......
......@@ -8,6 +8,7 @@ instance Show a => Show [a] -- Defined in ‘GHC.Show’
instance Applicative [] -- Defined in ‘GHC.Base’
instance Foldable [] -- Defined in ‘Data.Foldable’
instance Traversable [] -- Defined in ‘Data.Traversable’
instance Monoid [a] -- Defined in ‘GHC.Base’
data () = () -- Defined in ‘GHC.Tuple’
instance Bounded () -- Defined in ‘GHC.Enum’
instance Enum () -- Defined in ‘GHC.Enum’
......@@ -15,6 +16,7 @@ instance Eq () -- Defined in ‘GHC.Classes’
instance Ord () -- Defined in ‘GHC.Classes’
instance Read () -- Defined in ‘GHC.Read’
instance Show () -- Defined in ‘GHC.Show’
instance Monoid () -- Defined in ‘GHC.Base’
data (,) a b = (,) a b -- Defined in ‘GHC.Tuple’
instance (Bounded a, Bounded b) => Bounded (a, b)
-- Defined in ‘GHC.Enum’
......@@ -23,7 +25,8 @@ instance Functor ((,) a) -- Defined in ‘GHC.Base’
instance (Ord a, Ord b) => Ord (a, b) -- Defined in ‘GHC.Classes’
instance (Read a, Read b) => Read (a, b) -- Defined in ‘GHC.Read’
instance (Show a, Show b) => Show (a, b) -- Defined in ‘GHC.Show’
instance GHC.Base.Monoid a => Applicative ((,) a)
-- Defined in ‘GHC.Base’
instance Monoid a => Applicative ((,) a) -- Defined in ‘GHC.Base’
instance Foldable ((,) a) -- Defined in ‘Data.Foldable’
instance Traversable ((,) a) -- Defined in ‘Data.Traversable’
instance (Monoid a, Monoid b) => Monoid (a, b)
-- Defined in ‘GHC.Base’
......@@ -2,3 +2,4 @@ data (->) a b -- Defined in ‘GHC.Prim’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
instance Functor ((->) r) -- Defined in ‘GHC.Base’
instance Applicative ((->) a) -- Defined in ‘GHC.Base’
instance Monoid b => Monoid (a -> b) -- Defined in ‘GHC.Base’
......@@ -5,6 +5,7 @@ module Main(main) where
import Control.Monad.Fix
import Control.Monad.ST
import Data.STRef
import Prelude hiding (traverse)
newtype Node s a = N (STRef s Bool, Node s a, a, Node s a)
......
......@@ -15,6 +15,7 @@ import Control.Monad
import Control.Monad.Trans.State
import Data.List
import Data.Ord
import Prelude hiding (traverse)
type Traverse a = State (SrcSpan, [(Name, SrcSpan)]) a
......
......@@ -2,6 +2,7 @@
module DfltProb1 where
import Control.Monad.ST
import Prelude hiding (traverse)
traverse :: a -> ST s [a]
traverse = undefined
......
......@@ -17,7 +17,6 @@ import System.IO (localeEncoding)
import Data.List
import Data.Maybe(fromJust)
import Data.Array
import Data.Monoid
import Control.Monad
import qualified Data.Set as Set
......
......@@ -19,7 +19,6 @@
module Main (main) where
import Control.Exception
import Data.Monoid
import System.Directory
import System.Environment
import System.Exit
......
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