summaryrefslogtreecommitdiff
path: root/libraries/base/Text/ParserCombinators/ReadPrec.hs
diff options
context:
space:
mode:
authorAustin Seipp <austin@well-typed.com>2014-04-22 06:09:40 -0500
committerAustin Seipp <austin@well-typed.com>2014-09-09 08:13:27 -0500
commitd94de87252d0fe2ae97341d186b03a2fbe136b04 (patch)
tree1cac19f2786b1d8a1626886cd6373946a3a276b0 /libraries/base/Text/ParserCombinators/ReadPrec.hs
parentfdfe6c0e50001add357475a1a3a7627243a28a70 (diff)
downloadhaskell-d94de87252d0fe2ae97341d186b03a2fbe136b04.tar.gz
Make Applicative a superclass of Monad
Summary: This includes pretty much all the changes needed to make `Applicative` a superclass of `Monad` finally. There's mostly reshuffling in the interests of avoid orphans and boot files, but luckily we can resolve all of them, pretty much. The only catch was that Alternative/MonadPlus also had to go into Prelude to avoid this. As a result, we must update the hsc2hs and haddock submodules. Signed-off-by: Austin Seipp <austin@well-typed.com> Test Plan: Build things, they might not explode horribly. Reviewers: hvr, simonmar Subscribers: simonmar Differential Revision: https://phabricator.haskell.org/D13
Diffstat (limited to 'libraries/base/Text/ParserCombinators/ReadPrec.hs')
-rw-r--r--libraries/base/Text/ParserCombinators/ReadPrec.hs17
1 files changed, 12 insertions, 5 deletions
diff --git a/libraries/base/Text/ParserCombinators/ReadPrec.hs b/libraries/base/Text/ParserCombinators/ReadPrec.hs
index 235436c4d6..7098b50531 100644
--- a/libraries/base/Text/ParserCombinators/ReadPrec.hs
+++ b/libraries/base/Text/ParserCombinators/ReadPrec.hs
@@ -16,9 +16,9 @@
-----------------------------------------------------------------------------
module Text.ParserCombinators.ReadPrec
- (
+ (
ReadPrec,
-
+
-- * Precedences
Prec,
minPrec,
@@ -61,7 +61,7 @@ import qualified Text.ParserCombinators.ReadP as ReadP
, pfail
)
-import Control.Monad( MonadPlus(..) )
+import Control.Monad( MonadPlus(..), Alternative(..) )
import GHC.Num( Num(..) )
import GHC.Base
@@ -75,17 +75,24 @@ newtype ReadPrec a = P (Prec -> ReadP a)
instance Functor ReadPrec where
fmap h (P f) = P (\n -> fmap h (f n))
+instance Applicative ReadPrec where
+ pure = return
+ (<*>) = ap
+
instance Monad ReadPrec where
return x = P (\_ -> return x)
fail s = P (\_ -> fail s)
P f >>= k = P (\n -> do a <- f n; let P f' = k a in f' n)
-
+
instance MonadPlus ReadPrec where
mzero = pfail
mplus = (+++)
+instance Alternative ReadPrec where
+ empty = mzero
+ (<|>) = mplus
+
-- precedences
-
type Prec = Int
minPrec :: Prec