@@ -0,0 +1,27 @@
1+-- We use fromStreamK/toStreamK to convert the direct style stream to CPS
2+-- style. In the first phase we try fusing the fromStreamK/toStreamK using:
3+--
4+-- {-# RULES "fromStreamK/toStreamK fusion"
5+-- forall s. toStreamK (fromStreamK s) = s #-}
6+--
7+-- If for some reason some of the operations could not be fused then we have
8+-- fallback rules in the second phase. For example:
9+--
10+-- {-# INLINE_EARLY unfoldr #-}
11+-- unfoldr :: (Monad m, IsStream t) => (b -> Maybe (a, b)) -> b -> t m a
12+-- unfoldr step seed = fromStreamS (S.unfoldr step seed)
13+-- {-# RULES "unfoldr fallback to StreamK" [1]
14+-- forall a b. S.toStreamK (S.unfoldr a b) = K.unfoldr a b #-}```
15+--
16+-- Then, fromStreamK/toStreamK are inlined in the last phase:
17+--
18+-- {-# INLINE_LATE toStreamK #-}
19+-- toStreamK :: Monad m => Stream m a -> K.Stream m a```
20+--
21+-- The fallback rules make sure that if we could not fuse the direct style
22+-- operations then better use the CPS style operation, because unfused direct
23+-- style would have worse performance than the CPS style ops.
24+
25+#define INLINE_EARLY INLINE [2]
26+#define INLINE_NORMAL INLINE [1]
27+#define INLINE_LATE INLINE [0]