File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed
dunai/src/Data/MonadicStreamFunction/Instances Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change 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
3536instance 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'.
3841instance (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')
You can’t perform that action at this time.
0 commit comments