[Haskell-cafe] Re: Lazy data from pipe using MissingH module

John Goerzen jgoerzen at complete.org
Thu Nov 30 08:47:42 EST 2006

Dougal Stanton wrote:

> Newbie here working on a little program for fetching podcasts. I've been
> using the MissingH.Cmd module in concert with curl to download the RSS
> feeds like this:

First off, check out http://quux.org/devel/hpodder -- it is a podcast
downloader written in Haskell that uses MissingH.Cmd.  And Curl,  Might
just do what you want.

>> fetchFeed :: Subscription -> IO (Either Error [Episode])
>> fetchFeed sub = do
>>     (pid, feed)  <- pipeFrom "curl" (curlOpts ++
>>                              ["--url", (slocation sub)])
>>     let eps = parseEpisodes (stitle sub) feed
>>     forceSuccess pid
>>     return eps
> According to the API docs I have to forceSuccess pid *after* I use the
> data. Will this construct do that, or does the compiler have free reign
> to move the line beginning 'let ...' wherever it feels?

No, it won't.  I'd suggest adding something like:

  evaluate (length eps) 

before the forceSuccess.

What happens is that, since Haskell is lazy, it won't actually consume the
data from the pipe until it is needed -- which looks like it could even be
after this function returns.

forceSuccess waits for the process to die.  The process won't die until
you've consumed all its output.  Therefore your program will hang at

-- John

More information about the Haskell-Cafe mailing list