Control.Concurrent.Chan: how do i close a channel?

Claus Reinke claus.reinke at
Mon Jul 16 08:32:24 EDT 2007

>> however, i seem to be missing a way to close a channel?
>> am i misinterpreting this library?
> They're not attached to Handles -- that's the IO loop that does the
> writing to the Chan's job -- so they dont' really have a 'close'.

i was indeed looking for a haskell-internal replacement for Handles,
being somewhat surprised that i can't seem to create unattached
Handles with the uls (usual library suspects;-).

think pipes: if an external process takes input via a handle and provides
output via a handle, the haskell equivalent could do the same via a Chan,
so it'd be easy to write mixed pipes.

> When you're done writing, just stop writing.

yes, but any user of getChanContents will be left hanging! that kind
of function doesn't really work well without a way to tell it that it has
nothing more to wait for.

> I often use Chan (Maybe a), with Nothing to tell the reader thread that
> EOF is reached -- perhaps something like that is what you're looking
> for?

yes. but that would add another slight indirection, and it still doesn't
make getChanContents itself any more useable. if you "often" have to
modify/expand the API when you use it, perhaps there is something
missing in that API? the "much like hGetContents" comment does
seem to suggest that as well.


More information about the Libraries mailing list