Turning splitted pipes Producers into splitted Streams.

41 views
Skip to first unread message

Daniel Díaz

unread,
Feb 18, 2016, 4:38:33 PM2/18/16
to Haskell Pipes
Hi, I have the following doubt:

The documentation for the "streaming" package explains from to convert a pipes Producer into a Stream and back, but is it also possible to define a function with the following signature?

FreeT (Producer a IO) IO r -> Stream (Stream (Of a) IO) IO r

Tom Ellis

unread,
Feb 18, 2016, 5:10:30 PM2/18/16
to Haskell Pipes
On Thu, Feb 18, 2016 at 01:38:32PM -0800, Daniel Díaz wrote:
> The documentation for the "streaming
> <http://hackage.haskell.org/package/streaming>" package explains from to
> convert a pipes Producer into a Stream and back, but is it also possible to
> define a function with the following signature?
>
> FreeT (Producer a IO) IO r -> Stream (Stream (Of a) IO) IO r

I guess you can combine the following:

Free.iterTM Stream.wrap :: FreeT f m a -> Stream f m a
Streaming.unfoldr Pipes.next :: Producer a m r -> Stream (Of a) m r
maps :: (forall x . f x -> g x) -> Stream f m r -> Stream g m r

Tom

Michael Thompson

unread,
Feb 18, 2016, 9:05:32 PM2/18/16
to Haskell Pipes, tom-lists-hask...@jaguarpaw.co.uk
Right exactly

    import qualified Streaming as S
    import qualified Streaming.Prelude as S
    import qualified Control.Monad.Trans.Free as F
    import qualified Pipes as P
    import qualified Pipes.Prelude as P
    import qualified Pipes.Group as P


    fromFreeT :: (Monad m, Functor f) => F.FreeT f m a -> S.Stream f m a
    fromStream :: (Monad m, Functor f) => S.Stream f m a -> F.FreeT f m a
    fromProducers :: (Monad m) => 
       P.FreeT (P.Producer a m) m r -> S.Stream (S.Stream (S.Of a) m) m r
    fromStreams :: Monad m  => 
       S.Stream (S.Stream (S.Of a) m) m r -> P.FreeT (P.Producer a m) m r
   
    fromFreeT  = F.iterTM S.wrap
    fromStream = S.iterTM F.wrap
    fromProducers = S.maps (S.unfoldr P.next) . F.iterTM S.wrap 
    fromStreams   = P.maps (P.unfoldr S.next) . S.iterTM F.wrap


I was preferring the `unfold uncons` style over `fold cons` 
partly because I had a plan of convince the streaming io 
libraries to adopt this as a common incantation for interoperation
`fold` expressions tend already to be taken up and to suggest the
strict left fold in all of them. I wrote patches for io-streams and conduit 
but got lost thinking how best to argue for the plan. 
Part of the trouble is that `conduit` seems pretty 
suspicious of anything that would permit direct inspection of a source,
`io-streams`, `list-t` and company would have the different objection
that the functions would have no other use but interoperation.
Reply all
Reply to author
Forward
0 new messages