36 views

Skip to first unread message

Mar 14, 2018, 5:02:19 PM3/14/18

to Haskell Pipes

Hello,

I ran into an issue when trying to use `hoist` because of `forall` quantifier which won't work when the morphing function is specialized. Will appreciate pointers on how we can operate on the nested monad. The problem is described below.

`toSum :: Monad m `

=> Stream (Of (Either BS.ByteString BS.ByteString)) m r

-> Stream (Sum (Of BS.ByteString) (Of BS.ByteString)) m r

fromSum :: Monad m => Stream (Sum (Of BS.ByteString) (Of BS.ByteString)) m r -> Stream (Of (Either BS.ByteString BS.ByteString)) m r

transform :: (MonadIO m,Monad m) => Stream (Of BS.ByteString) m () -> Stream (Of BS.ByteString) m ()

-- Function to transform both Either byte streams

eitherTransform :: (MonadIO m,Monad m)

-> Stream (Of (Either BS.ByteString BS.ByteString)) m ()

-> Stream (Of (Either BS.ByteString BS.ByteString)) m ()

eitherTransform =

fromSum . unseparate . hoist transform . transform . separate . toSum

I also cribbed a `transLift` function from a StackOverflow post, but it doesn't seem to work on nested stream when used in place of `hoist` above:

`-- Function to operate on nested monad - no forall quantifier unlike hoist`

transLift :: (Monad m, Monad (t m), MonadTrans t) => (m a -> m b) -> t m a -> t m b

transLift f tma = tma >>= lift . f . return

I have other ways to access nested stream (like laid out in `Streaming` docs). However, I am curious what is good way to solve above problem where we want to combine the stream back after transformation.

Reply all

Reply to author

Forward

0 new messages

Search

Clear search

Close search

Google apps

Main menu