Commit 9db005a4 authored by Fumiaki Kinoshita's avatar Fumiaki Kinoshita 💬 Committed by Herbert Valerio Riedel
Browse files

Add Monad instance for `((,) a)` (#10190)

This was proposed a couple of times in the past, e.g.

 - https://mail.haskell.org/pipermail/libraries/2011-November/017153.html
 - https://mail.haskell.org/pipermail/libraries/2013-July/020446.html

but its implementation had been blocked by the fact that `Monoid` wasn't
in scope where the `Monad` class was defined. Since the AMP/FTP restructuring
this is no longer the case.
parent 33cfa5ff
......@@ -308,6 +308,9 @@ instance Monoid a => Applicative ((,) a) where
pure x = (mempty, x)
(u, f) <*> (v, x) = (u `mappend` v, f x)
instance Monoid a => Monad ((,) a) where
return x = (mempty, x)
(u, a) >>= k = case k a of (v, b) -> (u `mappend` v, b)
{- | The 'Functor' class is used for types that can be mapped over.
Instances of 'Functor' should satisfy the following laws:
......
......@@ -17,6 +17,8 @@
* `Dual`, `Product`, and `Sum` now have `Functor`, `Applicative`, and
`Monad` instances
* `(,) a` now has a `Monad` instance
* Redundant typeclass constraints have been removed:
- `Data.Ratio.{denominator,numerator}` have no `Integral` constraint anymore
- **TODO**
......
......@@ -15,6 +15,7 @@ data (,) a b = (,) a b -- Defined in ‘GHC.Tuple’
instance (Bounded a, Bounded b) => Bounded (a, b)
-- Defined in ‘GHC.Enum’
instance (Eq a, Eq b) => Eq (a, b) -- Defined in ‘GHC.Classes’
instance Monoid a => Monad ((,) a) -- Defined in ‘GHC.Base’
instance Functor ((,) a) -- Defined in ‘GHC.Base’
instance (Ord a, Ord b) => Ord (a, b) -- Defined in ‘GHC.Classes’
instance (Read a, Read b) => Read (a, b) -- Defined in ‘GHC.Read’
......
......@@ -21,6 +21,7 @@ data (,) a b = (,) a b -- Defined in ‘GHC.Tuple’
instance (Bounded a, Bounded b) => Bounded (a, b)
-- Defined in ‘GHC.Enum’
instance (Eq a, Eq b) => Eq (a, b) -- Defined in ‘GHC.Classes’
instance Monoid a => Monad ((,) a) -- Defined in ‘GHC.Base’
instance Functor ((,) a) -- Defined in ‘GHC.Base’
instance (Ord a, Ord b) => Ord (a, b) -- Defined in ‘GHC.Classes’
instance (Read a, Read b) => Read (a, b) -- Defined in ‘GHC.Read’
......
......@@ -10,7 +10,7 @@ tcfail181.hs:17:9:
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
...plus one other
...plus two others
In the expression: foo
In the expression: foo {bar = return True}
In an equation for ‘wog’: wog x = foo {bar = return True}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment