@@ -120,6 +120,9 @@ import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
120120data Stream m a =
121121 forall s. UnStream (State K.Stream m a -> s -> m (Step s a)) s
122122
123+-- XXX This causes perf trouble when pattern matching with "Stream" in a
124+-- recursive way, e.g. in uncons, foldBreak, concatMap. We need to get rid of
125+-- this.
123126unShare :: Stream m a -> Stream m a
124127unShare (UnStream step state) = UnStream step' state
125128 where step' gst = step (adaptState gst)
@@ -273,7 +276,7 @@ fold fld strm = do
273276
274277{-# INLINE_NORMAL foldBreak #-}
275278foldBreak :: Monad m => Fold m a b -> Stream m a -> m (b, Stream m a)
276−foldBreak (Fold fstep begin done) (Stream step state) = do
279+foldBreak (Fold fstep begin done) (UnStream step state) = do
277280 res <- begin
278281 case res of
279282 FL.Partial fs -> go SPEC fs state