From b4f84e4bfac3648864d9482b7585a01d44b5eb58 Mon Sep 17 00:00:00 2001 From: James Henri Haydon <james.haydon@gmail.com> Date: Fri, 28 Jul 2023 10:32:49 +0900 Subject: [PATCH] Explicit methods for Alternative Compose Explicitly define some and many in Alternative instance for Data.Functor.Compose Implementation of https://github.com/haskell/core-libraries-committee/issues/181 --- libraries/base/changelog.md | 1 + libraries/base/src/Data/Functor/Compose.hs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md index 4d7d76ae4788..f2b04008bf4f 100644 --- a/libraries/base/changelog.md +++ b/libraries/base/changelog.md @@ -11,6 +11,7 @@ * Export List from Data.List ([CLC proposal #182](https://github.com/haskell/core-libraries-committee/issues/182)). * Deprecate `Data.List.NonEmpty.unzip` ([CLC proposal #86](https://github.com/haskell/core-libraries-committee/issues/86)) * Fix exponent overflow/underflow bugs in the `Read` instances for `Float` and `Double` ([CLC proposal #192](https://github.com/haskell/core-libraries-committee/issues/192)) + * Implement `many` and `some` methods of `instance Alternative (Compose f g)` explicitly. ([CLC proposal #181](https://github.com/haskell/core-libraries-committee/issues/181)) * The functions `GHC.Exts.dataToTag#` and `GHC.Base.getTag` have had their types changed to the following: diff --git a/libraries/base/src/Data/Functor/Compose.hs b/libraries/base/src/Data/Functor/Compose.hs index ef2d305a7aab..2af347afdb8d 100644 --- a/libraries/base/src/Data/Functor/Compose.hs +++ b/libraries/base/src/Data/Functor/Compose.hs @@ -147,6 +147,10 @@ instance (Alternative f, Applicative g) => Alternative (Compose f g) where empty = Compose empty (<|>) = coerce ((<|>) :: f (g a) -> f (g a) -> f (g a)) :: forall a . Compose f g a -> Compose f g a -> Compose f g a + some = coerce (fmap sequenceA . some :: f (g a) -> f (g [a])) + :: forall a . Compose f g a -> Compose f g [a] + many = coerce (fmap sequenceA . many :: f (g a) -> f (g [a])) + :: forall a . Compose f g a -> Compose f g [a] -- | The deduction (via generativity) that if @g x :~: g y@ then @x :~: y@. -- -- GitLab