Tomasz Zielonka wrote:

On Tue, Jun 15, 2004 at 06:29:59PM -0400, S. Alexander Jacobson wrote:


 readEitherChan::Chan a -> Chan b -> Either a b

eitherChan a b left right = readEitherChan a b >>= either left right


... I think it would be safer to create once new Chan (Either a b), and then read from 
it.

createEitherChan :: Chan a -> Chan b -> IO (Chan (Either a b))


Although createEitherChan might be the best solution for some application, it would be interesting to know what the recommended way to implement the function eitherChan above is, if that is what you really need?

The eitherChan function corresponds to guarded nondeterministic choice, usually written (a?P)+(b?Q) process calculi, i.e., a rather fundamental concurrency operator.

Section 5 of [1] enumerates some reasons why guarded nondeterministic choice is not available as a primitive in Concurrent Haskell. Section 5.2 describes a function select for nondeterministic choice, but I don't see how to use that to implement readEitherChan (or takeEitherMVar)...

I got interested in this the other day when I was contemplating reviving Gadget Gofer [2], by porting it to Concurrent Haskell. Gadget Gofer has a non-deterministic choice operator, though, so the port would probably require more work than I expected...

--
Thomas H

[1] Concurrent Haskell
   http://www.haskell.org/ghc/docs/papers/concurrent-haskell.ps.gz
[2] Lazy Functional Components for Graphical User Interfaces,
   Rob Noble, PhD thesis, York, 1996


Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to