[commit: packages/Cabal] ghc-head: Add Functor/Applicative instances for ParseResult (f2bf834)
git at git.haskell.org
git at git.haskell.org
Mon Aug 26 23:28:05 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=f2bf8347bedb396ddb05d3333f35ac7df493bb5d
>---------------------------------------------------------------
commit f2bf8347bedb396ddb05d3333f35ac7df493bb5d
Author: Benno Fünfstück <benno.fuenfstueck at gmail.com>
Date: Wed Jul 10 19:23:29 2013 +0200
Add Functor/Applicative instances for ParseResult
ParseResult is a Monad, so it should also be a Functor and an Applicative.
>---------------------------------------------------------------
f2bf8347bedb396ddb05d3333f35ac7df493bb5d
Cabal/Distribution/ParseUtils.hs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/Cabal/Distribution/ParseUtils.hs b/Cabal/Distribution/ParseUtils.hs
index 26f5666..3923d77 100644
--- a/Cabal/Distribution/ParseUtils.hs
+++ b/Cabal/Distribution/ParseUtils.hs
@@ -88,6 +88,7 @@ import Data.Maybe (fromMaybe)
import Data.Tree as Tree (Tree(..), flatten)
import qualified Data.Map as Map
import Control.Monad (foldM)
+import Control.Applicative (Applicative(..))
import System.FilePath (normalise)
import Data.List (sortBy)
@@ -115,6 +116,14 @@ showPWarning fpath (UTFWarning line fname) =
data ParseResult a = ParseFailed PError | ParseOk [PWarning] a
deriving Show
+instance Functor ParseResult where
+ fmap f (ParseFailed err) = ParseFailed err
+ fmap f (ParseOk ws x) = ParseOk ws $ f x
+
+instance Applicative ParseResult where
+ pure = ParseOk []
+ f <*> a = join $ fmap (\f' -> fmap f' a)
+
instance Monad ParseResult where
return = ParseOk []
ParseFailed err >>= _ = ParseFailed err
More information about the ghc-commits
mailing list