[commit: packages/Cabal] ghc-head: More instances and use ap as default for (<*>) (016d133)
git at git.haskell.org
git at git.haskell.org
Mon Aug 26 23:28:14 CEST 2013
Repository : ssh://git@git.haskell.org/Cabal
On branch : ghc-head
Link : http://git.haskell.org/?p=packages/Cabal.git;a=commit;h=016d13352a9f5ea1d92ec0b98cad8a50f1211167
>---------------------------------------------------------------
commit 016d13352a9f5ea1d92ec0b98cad8a50f1211167
Author: Benno Fünfstück <benno.fuenfstueck at gmail.com>
Date: Wed Jul 10 20:30:18 2013 +0200
More instances and use ap as default for (<*>)
>---------------------------------------------------------------
016d13352a9f5ea1d92ec0b98cad8a50f1211167
Cabal/Distribution/Compat/ReadP.hs | 7 +++----
Cabal/Distribution/PackageDescription/Parse.hs | 10 +++++++++-
Cabal/Distribution/ParseUtils.hs | 5 +++--
Cabal/Distribution/Simple/BuildTarget.hs | 5 +++++
4 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/Cabal/Distribution/Compat/ReadP.hs b/Cabal/Distribution/Compat/ReadP.hs
index 5c1113c..44b970e 100644
--- a/Cabal/Distribution/Compat/ReadP.hs
+++ b/Cabal/Distribution/Compat/ReadP.hs
@@ -69,7 +69,7 @@ module Distribution.Compat.ReadP
)
where
-import Control.Monad( MonadPlus(..), liftM2 )
+import Control.Monad( MonadPlus(..), liftM2, ap )
import Data.Char (isSpace)
import Control.Applicative (Applicative(..))
@@ -93,8 +93,7 @@ instance Functor (P s) where
instance Applicative (P s) where
pure = return
-
- f <*> a = f >>= \f' -> fmap f' a
+ (<*>) = ap
instance Monad (P s) where
return x = Result x Fail
@@ -149,7 +148,7 @@ instance Functor (Parser r s) where
instance Applicative (Parser r s) where
pure = return
- f <*> a = f >>= \f' -> fmap f' a
+ (<*>) = ap
instance Monad (Parser r s) where
return x = R (\k -> k x)
diff --git a/Cabal/Distribution/PackageDescription/Parse.hs b/Cabal/Distribution/PackageDescription/Parse.hs
index 7197b1b..6a786c3 100644
--- a/Cabal/Distribution/PackageDescription/Parse.hs
+++ b/Cabal/Distribution/PackageDescription/Parse.hs
@@ -72,7 +72,8 @@ import Data.Char (isSpace)
import Data.Maybe (listToMaybe, isJust)
import Data.Monoid ( Monoid(..) )
import Data.List (nub, unfoldr, partition, (\\))
-import Control.Monad (liftM, foldM, when, unless)
+import Control.Monad (liftM, foldM, when, unless, ap)
+import Control.Applicative (Applicative(..))
import System.Directory (doesFileExist)
import qualified Data.ByteString.Lazy.Char8 as BS.Char8
@@ -602,6 +603,13 @@ buildInfoNames = map fieldName binfoFieldDescrs
-- on the 'mtl' package.
newtype StT s m a = StT { runStT :: s -> m (a,s) }
+instance Functor f => Functor (StT s f) where
+ fmap g (StT f) = StT $ \s -> fmap (\(a,s') -> (g a,s')) $ f s
+
+instance (Monad m, Functor m) => Applicative (StT s m) where
+ pure = return
+ (<*>) = ap
+
instance Monad m => Monad (StT s m) where
return a = StT (\s -> return (a,s))
StT f >>= g = StT $ \s -> do
diff --git a/Cabal/Distribution/ParseUtils.hs b/Cabal/Distribution/ParseUtils.hs
index 16ed6d6..07d91c7 100644
--- a/Cabal/Distribution/ParseUtils.hs
+++ b/Cabal/Distribution/ParseUtils.hs
@@ -87,7 +87,7 @@ import Data.Char (isSpace, toLower, isAlphaNum, isDigit)
import Data.Maybe (fromMaybe)
import Data.Tree as Tree (Tree(..), flatten)
import qualified Data.Map as Map
-import Control.Monad (foldM)
+import Control.Monad (foldM, ap)
import Control.Applicative (Applicative(..))
import System.FilePath (normalise)
import Data.List (sortBy)
@@ -122,7 +122,8 @@ instance Functor ParseResult where
instance Applicative ParseResult where
pure = ParseOk []
- f <*> a = f >>= \f' -> fmap f' a
+ (<*>) = ap
+
instance Monad ParseResult where
return = ParseOk []
diff --git a/Cabal/Distribution/Simple/BuildTarget.hs b/Cabal/Distribution/Simple/BuildTarget.hs
index daf1c64..68f5a77 100644
--- a/Cabal/Distribution/Simple/BuildTarget.hs
+++ b/Cabal/Distribution/Simple/BuildTarget.hs
@@ -55,6 +55,7 @@ import Data.Either
( partitionEithers )
import qualified Data.Map as Map
import Control.Monad
+import Control.Applicative (Applicative(..))
import qualified Distribution.Compat.ReadP as Parse
import Distribution.Compat.ReadP
( (+++), (<++) )
@@ -769,6 +770,10 @@ instance Functor Match where
fmap f (ExactMatch d xs) = ExactMatch d (fmap f xs)
fmap f (InexactMatch d xs) = InexactMatch d (fmap f xs)
+instance Applicative Match where
+ pure = return
+ (<*>) = ap
+
instance Monad Match where
return a = ExactMatch 0 [a]
NoMatch d ms >>= _ = NoMatch d ms
More information about the ghc-commits
mailing list