on master help sign in
Add streamList/unstreamList fusion rule
e9d0852Bryan O'Sullivan
Data/Text/Fusion/Common.hs+4−2
@@ -104,7 +104,7 @@ singleton c = Stream next False 1 -- HINT maybe too low
104{-# INLINE singleton #-}
104{-# INLINE singleton #-}
105
105
106streamList :: [a] -> Stream a
106streamList :: [a] -> Stream a
107−{-# INLINE streamList #-}
107+{-# INLINE [0] streamList #-}
108streamList [] = empty
108streamList [] = empty
109streamList s = Stream next s unknownLength
109streamList s = Stream next s unknownLength
110 where next [] = Done
110 where next [] = Done
@@ -112,13 +112,15 @@ streamList s = Stream next s unknownLength
112 unknownLength = 8 -- random HINT
112 unknownLength = 8 -- random HINT
113
113
114unstreamList :: Stream a -> [a]
114unstreamList :: Stream a -> [a]
115−{-# INLINE unstreamList #-}
115+{-# INLINE [0] unstreamList #-}
116unstreamList (Stream next s0 _len) = unfold s0
116unstreamList (Stream next s0 _len) = unfold s0
117 where unfold !s = case next s of
117 where unfold !s = case next s of
118 Done -> []
118 Done -> []
119 Skip s' -> unfold s'
119 Skip s' -> unfold s'
120 Yield x s' -> x : unfold s'
120 Yield x s' -> x : unfold s'
121
121
122+{-# RULES "STREAM streamList/unstreamList fusion" forall s. streamList (unstreamList s) = s #-}
123+
122-- ----------------------------------------------------------------------------
124-- ----------------------------------------------------------------------------
123-- * Basic stream functions
125-- * Basic stream functions
124
126