[Haskell-cafe] conduit: Inexhaustible source

David Turner dct25-561bs at mythic-beasts.com
Fri Feb 12 20:40:49 UTC 2016


Hi,

I've got a conduit thing that yields infinitely many values and never
exits, which I've given the type ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
()
o m Void - a bit like Source m o = ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
()
o m () except that it can't exit due to the Void.

(One side-question: why is Source m o not ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
Void
o m ()?)

I would now like to get the first item it yields; I'm currently using
Data.Conduit.List.head but of course this returns a Maybe o in case the
upstream thing exits. Is there a way to do this without that Maybe? I can't
see anything obvious, but nor can I think of a terribly good reason why not.

One thing that I was pondering was a kind of fuse operator with a type like
...

ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
a
b m r1 -> ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
b
c m r2 -> ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
a
c m (Either r1 r2)

... which returns the result of whichever thing exits first. Does such a
thing exist? Does it even make sense? If it existed, I think I could use it
here as it'd specialise to

ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
()
o m Void -> ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
o
Void m o -> ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
()
Void m (Either Void o)

and of course (Either Void o) is isomorphic to o so I'd be home and dry.

Having written this, I'm now also struggling to work out what the thing of
type ConduitM
<https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM>
o
Void m o would be. Maybe I'm going about this all the wrong way, or maybe
I'm just confused?

Any help greatly appreciated!

Cheers,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160212/e8b9aca2/attachment.html>


More information about the Haskell-Cafe mailing list