Coroutines
Simon Peyton-Jones
simonpj@microsoft.com
Mon, 19 Mar 2001 09:45:28 -0800
| What I had in mind was something like the following=20
| (pseudocode), which
| could easily be implemented on top of coroutines:
Concurrent Haskell provides exactly this Channel stuff.
Simon
|=20
| class Channel c t where
| send :: t -> c -> IO ()
| receive :: c -> IO t
|=20
| sender :: Int -> Channel -> ...
| sender n receiver =3D do send n receiver
| return (sender (n+1) receiver)
|=20
| receiver :: Channel -> ...
| receiver sender =3D do i <- receive sender
| return (receiver sender)
|=20
| c :: Channel Int
| c =3D ...
|=20
| main =3D run_them [ sender 1 c, receiver c ]
|=20
|=20
| Maybe there is also a way to achieve something similar using=20
| higher order
| functions---I just don't see how.
|=20
|=20
| > Or you may be interested in Concurrent Haskell
| > See section 4 of "Tackling the awkward squad"
| > http://research.microsoft.com/~simonpj/papers/marktoberdorf.htm
|=20
| Thanks, I'm chewing on this paper of yours since a couple of=20
| days already.
| I particularly like the introduction to monads---it's the=20
| best I have seen
| so far.
|=20
|=20
| --Andreas.
|=20
|=20