summaryrefslogtreecommitdiff
path: root/libraries/base
diff options
context:
space:
mode:
authorFumiaki Kinoshita <fumiexcel@gmail.com>2019-04-07 17:44:20 +0900
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-10-04 21:43:49 -0400
commitec93d2a90a2d4f189feafd21575b9e9ba5ba9a5d (patch)
tree392714d5c8508fb34e69967cdc428d047cb4d3ab /libraries/base
parent1357d02380641ba33b05eb87c80e6a4250cd4a3b (diff)
downloadhaskell-ec93d2a90a2d4f189feafd21575b9e9ba5ba9a5d.tar.gz
Add Monad instances to `(,,) a b` and `(,,,) a b c`
Diffstat (limited to 'libraries/base')
-rw-r--r--libraries/base/Data/Foldable.hs2
-rw-r--r--libraries/base/GHC/Base.hs26
-rw-r--r--libraries/base/changelog.md3
3 files changed, 31 insertions, 0 deletions
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index c17de972af..82bb3d9077 100644
--- a/libraries/base/Data/Foldable.hs
+++ b/libraries/base/Data/Foldable.hs
@@ -364,6 +364,8 @@ instance Foldable ((,) a) where
foldMap f (_, y) = f y
foldr f z (_, y) = f y z
+ length _ = 1
+ null _ = False
-- | @since 4.8.0.0
instance Foldable (Array i) where
diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
index d63f5d1a86..54c6f91280 100644
--- a/libraries/base/GHC/Base.hs
+++ b/libraries/base/GHC/Base.hs
@@ -437,6 +437,32 @@ instance Monoid a => Applicative ((,) a) where
instance Monoid a => Monad ((,) a) where
(u, a) >>= k = case k a of (v, b) -> (u <> v, b)
+-- | @since 4.14.0.0
+instance Functor ((,,) a b) where
+ fmap f (a, b, c) = (a, b, f c)
+
+-- | @since 4.14.0.0
+instance (Monoid a, Monoid b) => Applicative ((,,) a b) where
+ pure x = (mempty, mempty, x)
+ (a, b, f) <*> (a', b', x) = (a <> a', b <> b', f x)
+
+-- | @since 4.14.0.0
+instance (Monoid a, Monoid b) => Monad ((,,) a b) where
+ (u, v, a) >>= k = case k a of (u', v', b) -> (u <> u', v <> v', b)
+
+-- | @since 4.14.0.0
+instance Functor ((,,,) a b c) where
+ fmap f (a, b, c, d) = (a, b, c, f d)
+
+-- | @since 4.14.0.0
+instance (Monoid a, Monoid b, Monoid c) => Applicative ((,,,) a b c) where
+ pure x = (mempty, mempty, mempty, x)
+ (a, b, c, f) <*> (a', b', c', x) = (a <> a', b <> b', c <> c', f x)
+
+-- | @since 4.14.0.0
+instance (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) where
+ (u, v, w, a) >>= k = case k a of (u', v', w', b) -> (u <> u', v <> v', w <> w', b)
+
-- | @since 4.10.0.0
instance Semigroup a => Semigroup (IO a) where
(<>) = liftA2 (<>)
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index b97ed78ced..eeed94327e 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -36,6 +36,9 @@
* Add newtypes for `CSocklen` (`socklen_t`) and `CNfds` (`nfds_t`) to
`System.Posix.Types`.
+ * Add `Functor`, `Applicative` and `Monad` instances to `(,,) a b`
+ and `(,,,) a b c`
+
## 4.13.0.0 *TBA*
* Bundled with GHC *TBA*