[commit: packages/terminfo] ghc-head: Add missing Functor/Applicative/Alternative instances (8475af0)
git at git.haskell.org
git at git.haskell.org
Wed Jan 15 08:23:41 UTC 2014
Repository : ssh://git@git.haskell.org/terminfo
On branch : ghc-head
Link : http://git.haskell.org/packages/terminfo.git/commitdiff/8475af0b5c6a1ccf6ec6ff18bf8df6846c9b2911
>---------------------------------------------------------------
commit 8475af0b5c6a1ccf6ec6ff18bf8df6846c9b2911
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Sat Nov 2 20:22:50 2013 +0100
Add missing Functor/Applicative/Alternative instances
This is needed to silence GHC 7.8's AMP warnings, see also
http://www.haskell.org/haskellwiki/Functor-Applicative-Monad_Proposal#Missing_superclasses
for more information.
Signed-off-by: Herbert Valerio Riedel <hvr at gnu.org>
>---------------------------------------------------------------
8475af0b5c6a1ccf6ec6ff18bf8df6846c9b2911
System/Console/Terminfo/Base.hs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/System/Console/Terminfo/Base.hs b/System/Console/Terminfo/Base.hs
index 6c66574..24a4782 100644
--- a/System/Console/Terminfo/Base.hs
+++ b/System/Console/Terminfo/Base.hs
@@ -43,6 +43,7 @@ module System.Console.Terminfo.Base(
) where
+import Control.Applicative
import Control.Monad
import Data.Monoid
import Foreign.C
@@ -194,6 +195,10 @@ getCapability term (Capability f) = unsafePerformIO $ withCurTerm term (f term)
instance Functor Capability where
fmap f (Capability g) = Capability $ \t -> fmap (fmap f) (g t)
+instance Applicative Capability where
+ pure = return
+ (<*>) = ap
+
instance Monad Capability where
return = Capability . const . return . Just
Capability f >>= g = Capability $ \t -> do
@@ -202,6 +207,10 @@ instance Monad Capability where
Nothing -> return Nothing
Just x -> let Capability g' = g x in g' t
+instance Alternative Capability where
+ (<|>) = mplus
+ empty = mzero
+
instance MonadPlus Capability where
mzero = Capability (const $ return Nothing)
Capability f `mplus` Capability g = Capability $ \t -> do
More information about the ghc-commits
mailing list