Skip to content

Commit 64cee28

Browse files
committed
light refactor
1 parent 93e85c8 commit 64cee28

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

dunai/src/Data/MonadicStreamFunction/Instances/Profunctor.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE CPP #-}
22
{-# OPTIONS_GHC -fno-warn-orphans #-}
3+
{-# OPTIONS_GHC -ddump-simpl #-}
34

45
-- | Instances of 'Profunctor' and 'Traversing' for Monadic Stream Functions ('MSF').
56
--
@@ -35,11 +36,12 @@ instance Monad m => Strong (MSF m) where
3536
instance Monad m => Profunctor (MSF m) where
3637
dimap l r p = arr l >>> p >>> arr r
3738

39+
-- | This 'Traversing' instance will step the internal state of the 'MSF' once
40+
-- for every element of the input 'Traversable'.
3841
instance (Functor m, Applicative m, Monad m) => Traversing (MSF m) where
39-
traverse' (MSF msf) =
40-
let unMSF' x = StateT (\(MSF m) -> m x)
41-
in MSF $ \xs -> do
42+
traverse' msf =
43+
MSF $ \xs -> do
4244
-- `StateT (MSF m a b) m a` is isomorphic to `a -> m (b, MSF m a b)`, and
4345
-- `StateT`'s Applicative instance is needed for writing this traversal
44-
(fb, msf') <- runStateT (traverse unMSF' xs) (MSF msf)
46+
(fb, msf') <- runStateT (traverse (StateT . flip unMSF) xs) msf
4547
return (fb, traverse' msf')

0 commit comments

Comments
 (0)