summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2015-08-07 05:50:22 +0200
committerBen Gamari <ben@smart-cactus.org>2015-08-07 06:41:10 +0200
commita1c934c1b97a09db841d20da4811e0e1310f7511 (patch)
tree309e4d3f7bff929fe0e11babfa551ff6aceda573
parentbc43d23aa8a63ce64c2eeb5a2c74fb58c8f21356 (diff)
downloadhaskell-a1c934c1b97a09db841d20da4811e0e1310f7511.tar.gz
base: Add missing Traversable instance for ZipList
-rw-r--r--libraries/base/Control/Applicative.hs5
-rw-r--r--libraries/base/Data/Traversable.hs7
2 files changed, 9 insertions, 3 deletions
diff --git a/libraries/base/Control/Applicative.hs b/libraries/base/Control/Applicative.hs
index 39b6466b53..a2f342f83f 100644
--- a/libraries/base/Control/Applicative.hs
+++ b/libraries/base/Control/Applicative.hs
@@ -122,8 +122,9 @@ instance (ArrowZero a, ArrowPlus a) => Alternative (WrappedArrow a b) where
-- @f '<$>' 'ZipList' xs1 '<*>' ... '<*>' 'ZipList' xsn = 'ZipList' (zipWithn f xs1 ... xsn)@
--
newtype ZipList a = ZipList { getZipList :: [a] }
- deriving ( Show, Eq, Ord, Read, Functor, Foldable
- , Generic, Generic1)
+ deriving ( Show, Eq, Ord, Read, Functor
+ , Foldable, Generic, Generic1)
+-- See Data.Traversable for Traversabel instance due to import loops
instance Applicative ZipList where
pure x = ZipList (repeat x)
diff --git a/libraries/base/Data/Traversable.hs b/libraries/base/Data/Traversable.hs
index 535db00125..81e639cf37 100644
--- a/libraries/base/Data/Traversable.hs
+++ b/libraries/base/Data/Traversable.hs
@@ -46,7 +46,9 @@ module Data.Traversable (
foldMapDefault,
) where
-import Control.Applicative ( Const(..) )
+-- It is convenient to use 'Const' here but this means we must
+-- define a few instances here which really belong in Control.Applicative
+import Control.Applicative ( Const(..), ZipList(..) )
import Data.Either ( Either(..) )
import Data.Foldable ( Foldable )
import Data.Functor
@@ -217,6 +219,9 @@ instance Traversable First where
instance Traversable Last where
traverse f (Last x) = Last <$> traverse f x
+instance Traversable ZipList where
+ traverse f (ZipList x) = ZipList <$> traverse f x
+
-- general functions
-- | 'for' is 'traverse' with its arguments flipped. For a version