Skip to content

Commit 5ae0238

Browse files
committed
Make fmap fusable
1 parent c556a57 commit 5ae0238

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/Control/Monad/Logic/Sequence/Internal.hs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,23 @@ single a = return (a :< mzero)
219219

220220
instance Monad m => Functor (SeqT m) where
221221
{-# INLINEABLE fmap #-}
222-
fmap f (SeqT q) = SeqT $ fmap (liftM (fmap f)) q
223-
{-# INLINABLE (<$) #-}
224-
x <$ SeqT q = SeqT $ fmap (liftM (x <$)) q
222+
fmap = fmapSeqT
223+
224+
fmapSeqT :: Monad m => (a -> b) -> SeqT m a -> SeqT m b
225+
fmapSeqT f s = unstream (fmap_s f (stream s))
226+
{-# INLINEABLE [3] fmapSeqT #-}
227+
228+
fmap_s :: Monad m => (a -> b) -> StreamM m a -> StreamM m b
229+
fmap_s f (StreamM next_a a0) = StreamM next a0
230+
where
231+
{-# INLINE next #-}
232+
next a = do
233+
x <- next_a a
234+
case x of
235+
Done -> return Done
236+
Skip s -> return (Skip s)
237+
Yield y ys -> return (Yield (f y) ys)
238+
{-# INLINEABLE [1] fmap_s #-}
225239

226240
instance Monad m => Applicative (SeqT m) where
227241
{-# INLINE pure #-}

0 commit comments

Comments
 (0)