[Haskell-cafe] readEitherChan

Thomas Hallgren hallgren at cse.ogi.edu
Fri Jun 18 22:06:14 EDT 2004


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20040618/7445c2ee/signature.bin


More information about the Haskell-Cafe mailing list