Commit c617c1fb authored by Jack Henahan's avatar Jack Henahan Committed by Ben Gamari

base: Add Foldable and Traversable instances for Alt

Add Foldable and Traversable instances for Data.Monoid.Alt
Signed-off-by: Jack Henahan's avatarJack Henahan <jhenahan@me.com>

Reviewers: hvr, bgamari

Reviewed By: bgamari

Subscribers: mpickering, rwbarton, thomie, carter

GHC Trac Issues: #15099

Differential Revision: https://phabricator.haskell.org/D4698
parent d78dde9f
......@@ -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
......
......@@ -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
......
......@@ -19,6 +19,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
......
......@@ -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
......
......@@ -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)
......
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