[Haskell-cafe] Streaming a Conduit into a lazy list
Jules Bean
jules at jellybean.co.uk
Wed Nov 4 17:28:21 UTC 2015
On 4 Nov 2015, at 13:04, Michael Snoyman <michael at snoyman.com> wrote:
> This got me curious, so I just added a `sourceToList` function to master:
>
> https://github.com/snoyberg/conduit/commit/289f671cb7669c4aec78d8e77f01f2ace165d73a
Having spent a day thinking this over…
Nothing with the type `Source m a -> m [a]` can work for my second example - the one where I use runExceptionT to discharge the MonadThrow constraint. This is because once you use runExceptionT you have pushed yourself into the situation where in case of error there is no ‘return value’.
It’s not that I care about that per se - if there is an error then the return value is no use to me - but unfortunately that has knock-on implications on laziness.
The Writer monad solution pushes out the return value incrementally by a ‘side-channel’ rather than using the return value and it’s that property which lets it work even in the presence of runExceptionT.
Another approach which would work though is to provide a newtyped Identity monad which handles MonadThrow by _|_, which would allow you to regain laziness (?)
Jules
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151104/e3585531/attachment.html>
More information about the Haskell-Cafe
mailing list