Use-cases for non-empty pipes

21 views
Skip to first unread message

Aristid Breitkreuz

unread,
Aug 14, 2012, 4:57:05 PM8/14/12
to streamin...@googlegroups.com
Hi Streaming Haskellers,

I've devised a little scheme for pipes whose output is provably non-empty, but Michael thinks the use case is too narrow for this type to be really interesting. However my use case really is just this, and an unfold is already a pretty general generator... Well, I'm interested in your opinion on how versatile this might really be.

Let me first introduce the relevant types (you can find my full implementation for conduits at https://github.com/aristidb/conduit/blob/master/conduit/Data/Conduit/NonEmpty.hs).

I'm again using pipes-like types here, and this pseudo-code is untested:

newtype NonEmptyPipe i o m a = NonEmptyPipe (m (o, Pipe i o m a))

fold1 :: Monad m => (b -> a -> b) -> (a -> b) -> NonEmptyPipe i a m r -> Pipe i voidy m b -- can use runPipe on this

unfoldM1 :: Monad m => (b -> m (a, Maybe b)) -> b -> NonEmptyPipe () a m ()


The type of NonEmptyPipe statically guarantees that either it yields an output, or some kind of exception is thrown. (Depending on the monad it might do crazier things, but I'm assuming a "sane" monad here. No Cont allowed in these halls!)

Note that it also cannot by construction take any input before yielding that first output, because that input might never come.

So what do you think about this construction? Would you change it to make it more general? Do you think there are other ways to use it than just with folds and unfolds?


Aristid
Reply all
Reply to author
Forward
0 new messages