Skip to content

Commit e8876c6

Browse files
committed
io-sim: optimize Bifoldable instance of Trace
1 parent 99e2a11 commit e8876c6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

io-sim/src/Data/List/Trace.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ instance Bifoldable Trace where
7272
bifoldMap f g (Cons b bs) = g b <> bifoldMap f g bs
7373
bifoldMap f _ (Nil a) = f a
7474

75+
bifoldr f g c = go
76+
where
77+
go (Cons b bs) = b `g` go bs
78+
go (Nil a) = a `f` c
79+
{-# INLINE[0] bifoldr #-}
80+
81+
bifoldl f g = go
82+
where
83+
go c (Cons b bs) = go (c `g` b) bs
84+
go c (Nil a) = c `f` a
85+
{-# INLINE[0] bifoldl #-}
86+
7587
instance Bitraversable Trace where
7688
bitraverse f g (Cons b bs) = Cons <$> g b <*> bitraverse f g bs
7789
bitraverse f _ (Nil a) = Nil <$> f a

0 commit comments

Comments
 (0)