summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2014-09-18 23:05:40 +0200
committerHerbert Valerio Riedel <hvr@gnu.org>2014-09-18 23:12:57 +0200
commita94dc4c3067c6a0925e2e39f35ef0930771535f1 (patch)
treed96b8f833afd8e7ba7ea987f9cd1c7257a409f3b /libraries
parenteae19112462fe77a3f1298bff12b409b205a581d (diff)
downloadhaskell-a94dc4c3067c6a0925e2e39f35ef0930771535f1.tar.gz
Move Applicative/MonadPlus into GHC.Base
This is necessary in order to invert the import-dependency between Data.Foldable and Control.Monad (for addressing #9586) This also updates the `binary` submodule to qualify a GHC.Base import Reviewed By: austin Differential Revision: https://phabricator.haskell.org/D223
Diffstat (limited to 'libraries')
-rw-r--r--libraries/base/Control/Applicative.hs9
-rw-r--r--libraries/base/Control/Monad.hs72
-rw-r--r--libraries/base/Data/Data.hs1
-rw-r--r--libraries/base/Data/Foldable.hs6
-rw-r--r--libraries/base/Data/Typeable/Internal.hs5
-rw-r--r--libraries/base/GHC/Base.lhs71
-rw-r--r--libraries/base/GHC/Conc/Sync.lhs1
-rw-r--r--libraries/base/GHC/Enum.lhs2
-rw-r--r--libraries/base/GHC/Event/Array.hs2
-rw-r--r--libraries/base/GHC/Event/PSQ.hs2
-rw-r--r--libraries/base/System/IO/Error.hs4
-rw-r--r--libraries/base/Text/ParserCombinators/ReadP.hs4
-rw-r--r--libraries/base/Text/ParserCombinators/ReadPrec.hs1
m---------libraries/binary0
14 files changed, 84 insertions, 96 deletions
diff --git a/libraries/base/Control/Applicative.hs b/libraries/base/Control/Applicative.hs
index 7bab7294fb..accf58f561 100644
--- a/libraries/base/Control/Applicative.hs
+++ b/libraries/base/Control/Applicative.hs
@@ -49,18 +49,15 @@ module Control.Applicative (
import Control.Category
import Control.Arrow
-import Control.Monad (liftM, ap, Monad(..), MonadPlus(..), Alternative(..))
-import Data.Functor ((<$>), (<$))
import Data.Maybe
-import Data.Monoid (Monoid(..))
import Data.Tuple
import Data.Eq
import Data.Ord
-import Data.Functor (Functor(..))
+import Data.Functor ((<$>))
-import GHC.Base (const, Applicative(..),liftA, liftA2, liftA3, (<**>))
+import GHC.Base hiding ((.), id)
import GHC.Generics
-import GHC.List (map, repeat, zipWith)
+import GHC.List (repeat, zipWith)
import GHC.Read (Read)
import GHC.Show (Show)
diff --git a/libraries/base/Control/Monad.hs b/libraries/base/Control/Monad.hs
index 698d620800..534e6527d0 100644
--- a/libraries/base/Control/Monad.hs
+++ b/libraries/base/Control/Monad.hs
@@ -81,8 +81,6 @@ import Data.Maybe
import GHC.List
import GHC.Base
-infixl 3 <|>
-
-- -----------------------------------------------------------------------------
-- Prelude monad functions
@@ -111,76 +109,6 @@ mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
mapM_ f as = sequence_ (map f as)
-- -----------------------------------------------------------------------------
--- The Alternative class definition
-
--- | A monoid on applicative functors.
---
--- Minimal complete definition: 'empty' and '<|>'.
---
--- If defined, 'some' and 'many' should be the least solutions
--- of the equations:
---
--- * @some v = (:) '<$>' v '<*>' many v@
---
--- * @many v = some v '<|>' 'pure' []@
-class Applicative f => Alternative f where
- -- | The identity of '<|>'
- empty :: f a
- -- | An associative binary operation
- (<|>) :: f a -> f a -> f a
-
- -- | One or more.
- some :: f a -> f [a]
- some v = some_v
- where
- many_v = some_v <|> pure []
- some_v = (fmap (:) v) <*> many_v
-
- -- | Zero or more.
- many :: f a -> f [a]
- many v = many_v
- where
- many_v = some_v <|> pure []
- some_v = (fmap (:) v) <*> many_v
-
-instance Alternative Maybe where
- empty = Nothing
- Nothing <|> r = r
- l <|> _ = l
-
-instance Alternative [] where
- empty = []
- (<|>) = (++)
-
-
--- -----------------------------------------------------------------------------
--- The MonadPlus class definition
-
--- | Monads that also support choice and failure.
-class (Alternative m, Monad m) => MonadPlus m where
- -- | the identity of 'mplus'. It should also satisfy the equations
- --
- -- > mzero >>= f = mzero
- -- > v >> mzero = mzero
- --
- mzero :: m a
- mzero = empty
-
- -- | an associative operation
- mplus :: m a -> m a -> m a
- mplus = (<|>)
-
-instance MonadPlus [] where
- mzero = []
- mplus = (++)
-
-instance MonadPlus Maybe where
- mzero = Nothing
-
- Nothing `mplus` ys = ys
- xs `mplus` _ys = xs
-
--- -----------------------------------------------------------------------------
-- Functions mandated by the Prelude
-- | @'guard' b@ is @'return' ()@ if @b@ is 'True',
diff --git a/libraries/base/Data/Data.hs b/libraries/base/Data/Data.hs
index c6ee6f0f04..c2ce58dd6a 100644
--- a/libraries/base/Data/Data.hs
+++ b/libraries/base/Data/Data.hs
@@ -107,7 +107,6 @@ module Data.Data (
------------------------------------------------------------------------------
-import Control.Monad ( MonadPlus(..) )
import Data.Either
import Data.Eq
import Data.Maybe
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index 4e6681a542..0e655de573 100644
--- a/libraries/base/Data/Foldable.hs
+++ b/libraries/base/Data/Foldable.hs
@@ -58,8 +58,7 @@ module Data.Foldable (
find
) where
-import Control.Applicative
-import Control.Monad ( Monad(..), MonadPlus(..) )
+import Control.Applicative ( Const )
import Data.Bool
import Data.Either
import Data.Eq
@@ -70,8 +69,7 @@ import Data.Ord
import Data.Proxy
import GHC.Arr ( Array(..), Ix(..), elems )
-import GHC.Base ( (.), ($!), error, flip, id )
-import GHC.Exts ( build )
+import GHC.Base hiding ( foldr )
import GHC.Num ( Num(..) )
-- | Data structures that can be folded.
diff --git a/libraries/base/Data/Typeable/Internal.hs b/libraries/base/Data/Typeable/Internal.hs
index 1a901792c1..4e72bc4015 100644
--- a/libraries/base/Data/Typeable/Internal.hs
+++ b/libraries/base/Data/Typeable/Internal.hs
@@ -74,8 +74,6 @@ import Text.ParserCombinators.ReadPrec ( ReadPrec )
import GHC.Float ( FFFormat, RealFloat, Floating )
import Data.Bits ( Bits, FiniteBits )
import GHC.Enum ( Bounded, Enum )
-import Control.Monad ( MonadPlus )
--- import Data.Int
import GHC.Fingerprint.Type
import {-# SOURCE #-} GHC.Fingerprint
@@ -422,9 +420,12 @@ deriving instance Typeable Ix
deriving instance Typeable Show
deriving instance Typeable Read
+deriving instance Typeable Alternative
+deriving instance Typeable Applicative
deriving instance Typeable Functor
deriving instance Typeable Monad
deriving instance Typeable MonadPlus
+deriving instance Typeable Monoid
deriving instance Typeable Typeable
diff --git a/libraries/base/GHC/Base.lhs b/libraries/base/GHC/Base.lhs
index 9d121bd1f7..70f589729e 100644
--- a/libraries/base/GHC/Base.lhs
+++ b/libraries/base/GHC/Base.lhs
@@ -598,6 +598,69 @@ instance Monad Maybe where
return = Just
fail _ = Nothing
+-- -----------------------------------------------------------------------------
+-- The Alternative class definition
+
+infixl 3 <|>
+
+-- | A monoid on applicative functors.
+--
+-- Minimal complete definition: 'empty' and '<|>'.
+--
+-- If defined, 'some' and 'many' should be the least solutions
+-- of the equations:
+--
+-- * @some v = (:) '<$>' v '<*>' many v@
+--
+-- * @many v = some v '<|>' 'pure' []@
+class Applicative f => Alternative f where
+ -- | The identity of '<|>'
+ empty :: f a
+ -- | An associative binary operation
+ (<|>) :: f a -> f a -> f a
+
+ -- | One or more.
+ some :: f a -> f [a]
+ some v = some_v
+ where
+ many_v = some_v <|> pure []
+ some_v = (fmap (:) v) <*> many_v
+
+ -- | Zero or more.
+ many :: f a -> f [a]
+ many v = many_v
+ where
+ many_v = some_v <|> pure []
+ some_v = (fmap (:) v) <*> many_v
+
+
+instance Alternative Maybe where
+ empty = Nothing
+ Nothing <|> r = r
+ l <|> _ = l
+
+-- -----------------------------------------------------------------------------
+-- The MonadPlus class definition
+
+-- | Monads that also support choice and failure.
+class (Alternative m, Monad m) => MonadPlus m where
+ -- | the identity of 'mplus'. It should also satisfy the equations
+ --
+ -- > mzero >>= f = mzero
+ -- > v >> mzero = mzero
+ --
+ mzero :: m a
+ mzero = empty
+
+ -- | an associative operation
+ mplus :: m a -> m a -> m a
+ mplus = (<|>)
+
+instance MonadPlus Maybe where
+ mzero = Nothing
+
+ Nothing `mplus` ys = ys
+ xs `mplus` _ys = xs
\end{code}
@@ -620,6 +683,14 @@ instance Monad [] where
m >> k = foldr ((++) . (\ _ -> k)) [] m
return x = [x]
fail _ = []
+
+instance Alternative [] where
+ empty = []
+ (<|>) = (++)
+
+instance MonadPlus [] where
+ mzero = []
+ mplus = (++)
\end{code}
A few list functions that appear here because they are used here.
diff --git a/libraries/base/GHC/Conc/Sync.lhs b/libraries/base/GHC/Conc/Sync.lhs
index 391d072a78..da9f376747 100644
--- a/libraries/base/GHC/Conc/Sync.lhs
+++ b/libraries/base/GHC/Conc/Sync.lhs
@@ -100,7 +100,6 @@ import Data.Typeable
#ifndef mingw32_HOST_OS
import Data.Dynamic
#endif
-import Control.Monad
import Data.Maybe
import GHC.Base
diff --git a/libraries/base/GHC/Enum.lhs b/libraries/base/GHC/Enum.lhs
index a6dae7a2f5..4e36ad4fec 100644
--- a/libraries/base/GHC/Enum.lhs
+++ b/libraries/base/GHC/Enum.lhs
@@ -28,7 +28,7 @@ module GHC.Enum(
) where
-import GHC.Base
+import GHC.Base hiding ( many )
import GHC.Char
import GHC.Integer
import GHC.Num
diff --git a/libraries/base/GHC/Event/Array.hs b/libraries/base/GHC/Event/Array.hs
index f0f261e4d5..e0e089f8d1 100644
--- a/libraries/base/GHC/Event/Array.hs
+++ b/libraries/base/GHC/Event/Array.hs
@@ -31,7 +31,7 @@ import Foreign.C.Types (CSize(..))
import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Ptr (Ptr, nullPtr, plusPtr)
import Foreign.Storable (Storable(..))
-import GHC.Base
+import GHC.Base hiding (empty)
import GHC.ForeignPtr (mallocPlainForeignPtrBytes, newForeignPtr_)
import GHC.Num (Num(..))
import GHC.Real (fromIntegral)
diff --git a/libraries/base/GHC/Event/PSQ.hs b/libraries/base/GHC/Event/PSQ.hs
index a623625761..3421b5a984 100644
--- a/libraries/base/GHC/Event/PSQ.hs
+++ b/libraries/base/GHC/Event/PSQ.hs
@@ -88,7 +88,7 @@ module GHC.Event.PSQ
, atMost
) where
-import GHC.Base
+import GHC.Base hiding (empty)
import GHC.Num (Num(..))
import GHC.Show (Show(showsPrec))
import GHC.Event.Unique (Unique)
diff --git a/libraries/base/System/IO/Error.hs b/libraries/base/System/IO/Error.hs
index 6b926aedf5..63997b8491 100644
--- a/libraries/base/System/IO/Error.hs
+++ b/libraries/base/System/IO/Error.hs
@@ -310,10 +310,6 @@ annotateIOError :: IOError
annotateIOError ioe loc hdl path =
ioe{ ioe_handle = hdl `mplus` ioe_handle ioe,
ioe_location = loc, ioe_filename = path `mplus` ioe_filename ioe }
- where
- mplus :: Maybe a -> Maybe a -> Maybe a
- Nothing `mplus` ys = ys
- xs `mplus` _ = xs
-- | The 'catchIOError' function establishes a handler that receives any
-- 'IOError' raised in the action protected by 'catchIOError'.
diff --git a/libraries/base/Text/ParserCombinators/ReadP.hs b/libraries/base/Text/ParserCombinators/ReadP.hs
index afdaba5fbe..3d2b39c57e 100644
--- a/libraries/base/Text/ParserCombinators/ReadP.hs
+++ b/libraries/base/Text/ParserCombinators/ReadP.hs
@@ -72,10 +72,10 @@ module Text.ParserCombinators.ReadP
)
where
-import Control.Monad ( Alternative(empty, (<|>)), MonadPlus(..), sequence )
+import Control.Monad ( sequence )
import {-# SOURCE #-} GHC.Unicode ( isSpace )
import GHC.List ( replicate, null )
-import GHC.Base
+import GHC.Base hiding ( many )
infixr 5 +++, <++
diff --git a/libraries/base/Text/ParserCombinators/ReadPrec.hs b/libraries/base/Text/ParserCombinators/ReadPrec.hs
index 7098b50531..52f4eafca9 100644
--- a/libraries/base/Text/ParserCombinators/ReadPrec.hs
+++ b/libraries/base/Text/ParserCombinators/ReadPrec.hs
@@ -61,7 +61,6 @@ import qualified Text.ParserCombinators.ReadP as ReadP
, pfail
)
-import Control.Monad( MonadPlus(..), Alternative(..) )
import GHC.Num( Num(..) )
import GHC.Base
diff --git a/libraries/binary b/libraries/binary
-Subproject 2647d42f19bedae46c020fc3af029073f5690d5
+Subproject f5f6fe72bd069a2b56dd52e645aad406c619552