Fuse the fairly common case of zipWith f xs xs
authorRoman Leshchinskiy <rl@cse.unsw.edu.au>
Wed, 2 Dec 2009 23:44:18 +0000 (23:44 +0000)
committerRoman Leshchinskiy <rl@cse.unsw.edu.au>
Wed, 2 Dec 2009 23:44:18 +0000 (23:44 +0000)
Data/Vector/Fusion/Stream/Monadic.hs

index 014f4f3..601ff8a 100644 (file)
@@ -399,6 +399,14 @@ zipWithM f (Stream stepa sa na) (Stream stepb sb nb)
                                  Skip    sb' -> return $ Skip (sa, sb', Just x)
                                  Done        -> return $ Done
 
+-- FIXME: This might expose an opportunity for inplace execution.
+{-# RULES
+
+"zipWithM xs xs [Vector.Stream]" forall f xs.
+  zipWithM f xs xs = mapM (\x -> f x x) xs
+
+  #-}
+
 -- | Zip three 'Stream's with the given function
 zipWith3 :: Monad m => (a -> b -> c -> d) -> Stream m a -> Stream m b -> Stream m c -> Stream m d
 {-# INLINE zipWith3 #-}