[Haskell-beginners] Closing a channel
Ertugrul Soeylemez
es at ertes.de
Fri May 13 10:02:31 CEST 2011
Lyndon Maydwell <maydwell at gmail.com> wrote:
> I'm trying to implement a program that accumulates a list of items
> through many IO actions, then use these in another part of the program
> as a list.
>
> I've found Control.Concurrent.Chan which seems to provide a nice
> abstraction with getChanContents :: Chan a -> IO [a], but there
> doesn't seem to be a way for the source to close the channel.
You don't close channels, but just read exactly as many items as you
write.
> Are channels the right abstraction for something like this? Should
> look in to (itter|enumer)at(or|ee)s instead... They seem to encompass
> this model, but look quite involved.
Iteratees are an abstraction /around/ a construct like Chan. They allow
you to split the input processing (in this case from the channel) into
three separate problems: Fetching, transforming and using the data. In
particular, they solve the problems of lazy IO.
To answer your question: MVar, Chan and STM would all solve your
problem, but in different ways. In general I try to avoid Chan, because
if your reading end is slower than your writing end, you may run into
resource problems.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
More information about the Beginners
mailing list