Skip to content

Commit c47b0a9

Browse files
committed
added MonadZip Vector instance and base version guard
1 parent 84b8f3e commit c47b0a9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Data/Vector.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ import Control.DeepSeq ( NFData, rnf )
168168
import Control.Monad ( MonadPlus(..), liftM, ap )
169169
import Control.Monad.ST ( ST )
170170
import Control.Monad.Primitive
171+
import Control.Monad.Zip
171172

172173
import Prelude hiding ( length, null,
173174
replicate, (++), concat,
@@ -312,6 +313,20 @@ instance MonadPlus Vector where
312313
{-# INLINE mplus #-}
313314
mplus = (++)
314315

316+
-- MonadZip was added in base-4.4.0
317+
#if MIN_VERSION_base(4,4,0)
318+
instance MonadZip Vector where
319+
{-# INLINE mzip #-}
320+
mzip = zip
321+
322+
{-# INLINE mzipWith #-}
323+
mzipWith = zipWith
324+
325+
{-# INLINE munzip #-}
326+
munzip = unzip
327+
#endif
328+
329+
315330
instance Applicative.Applicative Vector where
316331
{-# INLINE pure #-}
317332
pure = singleton

tests/Tests/Vector.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,17 @@ testPolymorphicFunctions _ = $(testProperties [
424424
constructrN xs n f = constructrN (f xs : xs) (n-1) f
425425

426426
testTuplyFunctions:: forall a v. (COMMON_CONTEXT(a, v), VECTOR_CONTEXT((a, a), v), VECTOR_CONTEXT((a, a, a), v)) => v a -> [Test]
427-
testTuplyFunctions _ = $(testProperties ['prop_zip, 'prop_zip3, 'prop_unzip, 'prop_unzip3])
427+
testTuplyFunctions _ = $(testProperties [ 'prop_zip, 'prop_zip3, 'prop_mzip
428+
, 'prop_unzip, 'prop_unzip3, 'prop_munzip])
428429
where
429430
prop_zip :: P (v a -> v a -> v (a, a)) = V.zip `eq` zip
430431
prop_zip3 :: P (v a -> v a -> v a -> v (a, a, a)) = V.zip3 `eq` zip3
432+
prop_mzip :: P (Data.Vector.Vector a -> Data.Vector.Vector a -> Data.Vector.Vector (a, a))
433+
= V.zip `eq` zip
431434
prop_unzip :: P (v (a, a) -> (v a, v a)) = V.unzip `eq` unzip
432435
prop_unzip3 :: P (v (a, a, a) -> (v a, v a, v a)) = V.unzip3 `eq` unzip3
436+
prop_munzip :: P (Data.Vector.Vector (a, a) -> (Data.Vector.Vector a, Data.Vector.Vector a))
437+
= V.unzip `eq` unzip
433438

434439
testOrdFunctions :: forall a v. (COMMON_CONTEXT(a, v), Ord a, Ord (v a)) => v a -> [Test]
435440
testOrdFunctions _ = $(testProperties

0 commit comments

Comments
 (0)