[commit: packages/base] master: Add `instance Monoid a => Monoid (Const a b)` (6f3a194)
git at git.haskell.org
git
Sat Oct 5 14:36:05 UTC 2013
Repository : ssh://git at git.haskell.org/base
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/6f3a194accd2a1a75a3f86c1b4dca30521488110/base
>---------------------------------------------------------------
commit 6f3a194accd2a1a75a3f86c1b4dca30521488110
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Sat Oct 5 15:40:28 2013 +0200
Add `instance Monoid a => Monoid (Const a b)`
For more details, see original proposal at
http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/20369
Signed-off-by: Herbert Valerio Riedel <hvr at gnu.org>
>---------------------------------------------------------------
6f3a194accd2a1a75a3f86c1b4dca30521488110
Control/Applicative.hs | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/Control/Applicative.hs b/Control/Applicative.hs
index 78e2b4b..dbfa272 100644
--- a/Control/Applicative.hs
+++ b/Control/Applicative.hs
@@ -230,6 +230,11 @@ newtype Const a b = Const { getConst :: a }
instance Functor (Const m) where
fmap _ (Const v) = Const v
+-- Added in base-4.7.0.0
+instance Monoid a => Monoid (Const a b) where
+ mempty = Const mempty
+ mappend (Const a) (Const b) = Const (mappend a b)
+
instance Monoid m => Applicative (Const m) where
pure _ = Const mempty
Const f <*> Const v = Const (f `mappend` v)
More information about the ghc-commits
mailing list