isEmptyChan blocks?

Volker Stolz stolz@i2.informatik.rwth-aachen.de
Sat, 21 Jun 2003 00:46:17 +0200


In local.glasgow-haskell-users, you wrote:
> That makes isEmptyChan essentially useless.  Either it should be
> removed, or the implementation of Chan needs to be elaborated to support
> isEmptyChan.

I have a new implementation here which should track the number of elements
in a channel, taking also into account unGetChan & dupChan. It seems to
work, but lacks thorough testing. In any case, as it bloats the data structure

data Chan a
 = Chan (MVar ([MVar Integer],Stream a))
        (MVar ([MVar Integer],Stream a))
	(MVar Integer)

type Stream a = MVar ([MVar Integer],ChItem a)

it should probably be something like Control.Concurrent.CountChan.

http://www.foldr.org/~stolz/Chan2.hs

Without documentation it's quite useless, I'll leave it over the weekend...
If nobody comes up with a more sensible solution, I'd say remove isEmptyChan
from the regular module.

[although I consider
   mapM_ (uncurry putMVar) (zip counts (map (+1) vs))
 rather neat :)]
-- 
http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME
rage against the finite state machine