<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><a name="-532126307_t:Source" style="font-size:13px;color:rgb(0,0,0);margin:0px;padding:0px;font-weight:bold;font-family:monospace;line-height:16.12px">Source</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> m o = </span><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" target="_blank" style="font-size:13px;color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none;font-family:monospace;line-height:16.12px">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> () o m ()</span><span style="font-size:12.8px">; why is </span><a name="-532126307_t:Source" style="color:rgb(0,0,0);font-size:13px;margin:0px;padding:0px;font-weight:bold;font-family:monospace;line-height:16.12px">Source</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> m o</span><span style="font-size:12.8px"> not </span><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" target="_blank" style="color:rgb(171,105,84);font-size:13px;margin:0px;padding:0px;text-decoration:none;font-family:monospace;line-height:16.12px">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> Void o m ()</span><span style="font-size:12.8px">?</span></blockquote><div><br></div><div>I can't think of a really good answer to this, but here's a mediocre answer: you can always "step" a ConduitM that is blocked on trivial input. So the promise of a Source is not that it never blocks, but rather, that it only blocks in such a way that it is trivial to unblock.</div><div><br></div><div>You may like the Producer type synonym better:</div><div><pre style="color:rgb(0,0,0)"><span class="" style="color:blue">type</span> <span class="">Producer</span> <span class="">m</span> <span class="">o</span> <span class="" style="color:red">=</span> <span class="" style="color:blue">forall</span> <span class="">i</span><span class="">.</span> <span class="">ConduitM</span> <span class="">i</span> <span class="">o</span> <span class="">m</span> <span class="">()</span></pre></div><div>When you have a Producer m o, it can be instantiated to ConduitM Void o m (), because you can select i = Void.</div><div><br></div><div>Now for your main question...</div><div><br></div>So the thing about ConduitM composition is that the "upstream result" must be (). If you peel away the ConduitM layer of abstraction and take a look at Data.Conduit.Internal.Pipe, you'll find the operator you're looking for:<div><br></div><div><a href="http://hackage.haskell.org/package/conduit-1.2.6.1/docs/src/Data-Conduit-Internal-Pipe.html#awaitE">http://hackage.haskell.org/package/conduit-1.2.6.1/docs/src/Data-Conduit-Internal-Pipe.html#awaitE</a><br></div><div><br></div><div><font face="monospace, monospace">awaitE :: <span class="" style="color:rgb(0,0,0)">Pipe</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:rgb(0,0,0)">l</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:rgb(0,0,0)">i</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:rgb(0,0,0)">o</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:rgb(0,0,0)">u</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:rgb(0,0,0)">m</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:red">(</span><span class="" style="color:rgb(0,0,0)">Either</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:rgb(0,0,0)">u</span><span style="color:rgb(0,0,0)"> </span><span class="" style="color:rgb(0,0,0)">i</span><span class="" style="color:red">)</span></font></div><div><font face="monospace, monospace"><span class="" style="color:red"><br></span></font></div>I'm not quite sure how to surface this into the ConduitM level of abstraction. </div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">-- Dan Burton</div></div>
<br><div class="gmail_quote">On Fri, Feb 12, 2016 at 12:40 PM, David Turner <span dir="ltr"><<a href="mailto:dct25-561bs@mythic-beasts.com" target="_blank">dct25-561bs@mythic-beasts.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I've got a conduit thing that yields infinitely many values and never exits, which I've given the type <a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84);font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> () o m Void</span> - a bit like <a name="-532126307_t:Source" style="font-size:13px;margin:0px;padding:0px;font-weight:bold;color:rgb(0,0,0);font-family:monospace;line-height:16.12px">Source</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> m o = </span><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84);font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> () o m ()</span> except that it can't exit due to the <span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)">Void</span>.</div><div><br></div><div>(One side-question: why is <a name="-532126307_t:Source" style="font-size:13px;color:rgb(0,0,0);margin:0px;padding:0px;font-weight:bold;font-family:monospace;line-height:16.12px">Source</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> m o</span> not <a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none;font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> Void o m ()</span>?)</div><div><br></div><div>I would now like to get the first item it yields; I'm currently using <font face="monospace, monospace">Data.Conduit.List.head</font> but of course this returns a <font face="monospace, monospace">Maybe o</font> in case the upstream thing exits. Is there a way to do this without that <font face="monospace, monospace">Maybe</font>? I can't see anything obvious, but nor can I think of a terribly good reason why not.<br></div><div><br></div><div>One thing that I was pondering was a kind of fuse operator with a type like ...</div><div><br></div><div><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84);font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> a b m r1 -> </span><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84);font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> b c m r2 -> </span><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;margin:0px;padding:0px;text-decoration:none;color:rgb(171,105,84);font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> a c m (Either r1 r2)</span></div><div><br></div><div>... 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</div><div><br></div><div><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none;font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> () o m Void -> </span><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none;font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> o Void m o -> </span><a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none;font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> () Void m (Either Void o)</span><br></div><div><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"><br></span></div><div>and of course <span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)">(Either Void o)</span> is isomorphic to <span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)">o</span> so I'd be home and dry.</div><div><br></div><div>Having written this, I'm now also struggling to work out what the thing of type <a href="https://hackage.haskell.org/package/conduit-1.2.6/docs/Data-Conduit.html#t:ConduitM" style="font-size:13px;color:rgb(171,105,84);margin:0px;padding:0px;text-decoration:none;font-family:monospace;line-height:16.12px" target="_blank">ConduitM</a><span style="font-size:13px;color:rgb(0,0,0);font-family:monospace;line-height:16.12px;background-color:rgb(240,240,240)"> o Void m o</span> would be. Maybe I'm going about this all the wrong way, or maybe I'm just confused?</div><div><br></div><div>Any help greatly appreciated!</div><div><br></div><div>Cheers,</div><div><br></div><div>David</div><div><br></div><div><br></div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>