[commit: ghc] master: base: Add Foldable and Traversable instances for Alt (c617c1f)
git at git.haskell.org
git at git.haskell.org
Sun May 20 15:42:20 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/c617c1fb9403dc80f95c8083db9d347ce839b70f/ghc
>---------------------------------------------------------------
commit c617c1fb9403dc80f95c8083db9d347ce839b70f
Author: Jack Henahan <jhenahan at me.com>
Date: Wed May 16 16:39:15 2018 -0400
base: Add Foldable and Traversable instances for Alt
Add Foldable and Traversable instances for Data.Monoid.Alt
Signed-off-by: Jack Henahan <jhenahan at me.com>
Reviewers: hvr, bgamari
Reviewed By: bgamari
Subscribers: mpickering, rwbarton, thomie, carter
GHC Trac Issues: #15099
Differential Revision: https://phabricator.haskell.org/D4698
>---------------------------------------------------------------
c617c1fb9403dc80f95c8083db9d347ce839b70f
libraries/base/Data/Foldable.hs | 4 ++++
libraries/base/Data/Traversable.hs | 8 +++++++-
libraries/base/changelog.md | 2 ++
testsuite/tests/polykinds/T13393.stderr | 2 +-
testsuite/tests/typecheck/should_fail/T10971b.stderr | 8 ++++----
5 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/libraries/base/Data/Foldable.hs b/libraries/base/Data/Foldable.hs
index 573d4c8..b3a46be 100644
--- a/libraries/base/Data/Foldable.hs
+++ b/libraries/base/Data/Foldable.hs
@@ -436,6 +436,10 @@ instance Foldable First where
instance Foldable Last where
foldMap f = foldMap f . getLast
+-- | @since 4.12.0.0
+instance (Foldable f) => Foldable (Alt f) where
+ foldMap f = foldMap f . getAlt
+
-- Instances for GHC.Generics
-- | @since 4.9.0.0
instance Foldable U1 where
diff --git a/libraries/base/Data/Traversable.hs b/libraries/base/Data/Traversable.hs
index 2a654b7..dcf7412 100644
--- a/libraries/base/Data/Traversable.hs
+++ b/libraries/base/Data/Traversable.hs
@@ -60,7 +60,8 @@ import Data.Foldable ( Foldable )
import Data.Functor
import Data.Functor.Identity ( Identity(..) )
import Data.Functor.Utils ( StateL(..), StateR(..) )
-import Data.Monoid ( Dual(..), Sum(..), Product(..), First(..), Last(..) )
+import Data.Monoid ( Dual(..), Sum(..), Product(..),
+ First(..), Last(..), Alt(..) )
import Data.Proxy ( Proxy(..) )
import GHC.Arr
@@ -289,6 +290,10 @@ instance Traversable First where
instance Traversable Last where
traverse f (Last x) = Last <$> traverse f x
+-- | @since 4.12.0.0
+instance (Traversable f) => Traversable (Alt f) where
+ traverse f (Alt x) = Alt <$> traverse f x
+
-- | @since 4.9.0.0
instance Traversable ZipList where
traverse f (ZipList x) = ZipList <$> traverse f x
@@ -296,6 +301,7 @@ instance Traversable ZipList where
-- | @since 4.9.0.0
deriving instance Traversable Identity
+
-- Instances for GHC.Generics
-- | @since 4.9.0.0
instance Traversable U1 where
diff --git a/libraries/base/changelog.md b/libraries/base/changelog.md
index d4b6261..6909220 100644
--- a/libraries/base/changelog.md
+++ b/libraries/base/changelog.md
@@ -20,6 +20,8 @@
* `Numeric.showEFloat (Just 0)` now respects the user's requested precision.
(#15115)
+ * `Data.Monoid.Alt` now has `Foldable` and `Traversable` instances. (#15099)
+
## 4.11.1.0 *TBA*
* Bundled with GHC 8.4.2
diff --git a/testsuite/tests/polykinds/T13393.stderr b/testsuite/tests/polykinds/T13393.stderr
index 26aa577..ca67007 100644
--- a/testsuite/tests/polykinds/T13393.stderr
+++ b/testsuite/tests/polykinds/T13393.stderr
@@ -8,7 +8,7 @@ T13393.hs:61:3: error:
instance Traversable Identity -- Defined in ‘Data.Traversable’
instance Traversable Maybe -- Defined in ‘Data.Traversable’
...plus two others
- ...plus 25 instances involving out-of-scope types
+ ...plus 26 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of a 'do' block:
mapM putBackLeftOverInputAndReturnOutput undefined
diff --git a/testsuite/tests/typecheck/should_fail/T10971b.stderr b/testsuite/tests/typecheck/should_fail/T10971b.stderr
index 2754a3f..2abbcb0 100644
--- a/testsuite/tests/typecheck/should_fail/T10971b.stderr
+++ b/testsuite/tests/typecheck/should_fail/T10971b.stderr
@@ -11,7 +11,7 @@ T10971b.hs:4:11: error:
instance Foldable Maybe -- Defined in ‘Data.Foldable’
instance Foldable ((,) a) -- Defined in ‘Data.Foldable’
...plus one other
- ...plus 26 instances involving out-of-scope types
+ ...plus 27 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: length x
In the expression: \ x -> length x
@@ -29,7 +29,7 @@ T10971b.hs:5:13: error:
instance Traversable Maybe -- Defined in ‘Data.Traversable’
instance Traversable ((,) a) -- Defined in ‘Data.Traversable’
...plus one other
- ...plus 26 instances involving out-of-scope types
+ ...plus 27 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: fmapDefault f x
In the expression: \ f x -> fmapDefault f x
@@ -47,7 +47,7 @@ T10971b.hs:6:14: error:
instance Traversable Maybe -- Defined in ‘Data.Traversable’
instance Traversable ((,) a) -- Defined in ‘Data.Traversable’
...plus one other
- ...plus 26 instances involving out-of-scope types
+ ...plus 27 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: fmapDefault f x
In the expression: (fmapDefault f x, length x)
@@ -65,7 +65,7 @@ T10971b.hs:6:31: error:
instance Foldable Maybe -- Defined in ‘Data.Foldable’
instance Foldable ((,) a) -- Defined in ‘Data.Foldable’
...plus one other
- ...plus 26 instances involving out-of-scope types
+ ...plus 27 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the expression: length x
In the expression: (fmapDefault f x, length x)
More information about the ghc-commits
mailing list