Question

The type signature for http is:

Why isn't it this instead?

If I understand correctly, an Iteratee x m a is like a monadic parser that consumes a stream of items of type x. It makes sense for http's callback to be an Iteratee, as it consumes the response body.

However, http itself does not appear to consume any input. The httpLbs function executes http with run_ (defined in Data.Enumerator). From what I can tell, run considers it an error if the iteratee given to it expects input:

So if http does not consume input, why is it an iteratee? Why isn't it just a MonadIO action?

Was it helpful?

Solution

  1. It's not an error to pass run (or run_) an Iteratee that expects input; that's why we first pass in enumEOF. It's invalid for an Iteratee to continue expecting input after receiving an EOF.
  2. By leaving the result of http in the Iteratee monad, you can perform multiple actions in the same pipeline, such as streaming two HTTP responses into a file.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top