Commit ec93d2a9 authored by Fumiaki Kinoshita's avatar Fumiaki Kinoshita 💬 Committed by Marge Bot
Browse files

Add Monad instances to `(,,) a b` and `(,,,) a b c`

parent 1357d023
Pipeline #10908 passed with stages
in 409 minutes and 2 seconds
......@@ -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
......
......@@ -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 (<>)
......
......@@ -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*
......
......@@ -53,6 +53,8 @@ instance Functor [] -- Defined in ‘GHC.Base’
instance Functor Maybe -- Defined in ‘GHC.Base’
instance Functor IO -- Defined in ‘GHC.Base’
instance ∀ r. Functor ((->) r) -- Defined in ‘GHC.Base’
instance ∀ a b c. Functor ((,,,) a b c) -- Defined in ‘GHC.Base’
instance ∀ a b. Functor ((,,) a b) -- Defined in ‘GHC.Base’
instance ∀ a. Functor ((,) a) -- Defined in ‘GHC.Base’
datatypeName
∷ ∀ {d} {t ∷ ★ → (★ → ★) → ★ → ★} {f ∷ ★ → ★} {a}.
......
......@@ -32,7 +32,7 @@ T10403.hs:22:15: warning: [-Wdeferred-type-errors (in -Wdefault)]
instance Functor IO -- Defined in ‘GHC.Base’
instance Functor (B t) -- Defined at T10403.hs:10:10
instance Functor I -- Defined at T10403.hs:6:10
...plus three others
...plus five others
...plus two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the second argument of ‘(.)’, namely ‘fmap (const ())’
......
......@@ -9,7 +9,7 @@ T13292a.hs:4:12: warning: [-Wdeferred-type-errors (in -Wdefault)]
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monoid a => Monad ((,) a) -- Defined in ‘GHC.Base’
...plus one other
...plus three others
...plus two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: return ()
......
......@@ -10,7 +10,7 @@ tcfail181.hs:17:9: error:
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monoid a => Monad ((,) a) -- Defined in ‘GHC.Base’
...plus one other
...plus three others
...plus two instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: foo
......
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