on master help sign in
Merge pull request #233 from composewell/fixrules

Fix a bug in zipWithM rule that causes effects to run only once.

commit476a85a2e64dadef0f6185ba774152d4a450bd5d authorHarendra Kumar <harendra.kumar@gmail.com> dateSat 3 Aug 2019, 05:19 (7 years ago) parentec39077c726ca3
2 files changed+11−1
src/Streamly/Streams/Instances.hs+1 src/Streamly/Streams/StreamD.hs+10−1
src/Streamly/Streams/Instances.hs+1
@@ -108,6 +108,7 @@ instance (a ~ Char) => IsString (STREAM Identity a) where { \
108108 fromString = P.fromList }; \
109109 \
110110instance NFData a => NFData (STREAM Identity a) where { \
111+ {-# INLINE rnf #-}; \
111112 rnf = runIdentity . P.foldl' (\_ x -> rnf x) () }; \
112113
113114-------------------------------------------------------------------------------
src/Streamly/Streams/StreamD.hs+10−1
@@ -12,6 +12,10 @@
1212{-# LANGUAGE RankNTypes #-}
1313{-# LANGUAGE MagicHash #-}
1414
15+#if __GLASGOW_HASKELL__ >= 801
16+{-# LANGUAGE TypeApplications #-}
17+#endif
18+
1519#include "inline.hs"
1620
1721-- |
@@ -255,6 +259,9 @@ import Control.Monad.Catch (MonadCatch)
255259import Control.Monad.IO.Class (MonadIO(..))
256260import Control.Monad.Trans (MonadTrans(lift))
257261import Data.Bits (shiftR, shiftL, (.|.), (.&.))
262+#if __GLASGOW_HASKELL__ >= 801
263+import Data.Functor.Identity (Identity)
264+#endif
258265import Data.Maybe (fromJust, isJust)
259266import Data.Word (Word32)
260267import Foreign.Ptr (Ptr)
@@ -2352,8 +2359,10 @@ zipWithM f (Stream stepa ta) (Stream stepb tb) = Stream step (ta, tb, Nothing)
23522359 Skip sb' -> return $ Skip (sa, sb', Just x)
23532360 Stop -> return Stop
23542361
2362+#if __GLASGOW_HASKELL__ >= 801
23552363{-# RULES "zipWithM xs xs"
2356− forall f xs. zipWithM f xs xs = mapM (\x -> f x x) xs #-}
2364+ forall f xs. zipWithM @Identity f xs xs = mapM (\x -> f x x) xs #-}
2365+#endif
23572366
23582367{-# INLINE zipWith #-}
23592368zipWith :: Monad m => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c