Coroutines

Richard Uhtenwoldt ru@river.org
Tue, 20 Mar 2001 23:40:28 -0800 (PST)


Andreas Gruenbacher writes:

>It's not what I had in mind, though. Simon's MVars (in the Awkward Squad)
>come pretty close, but they're still not the sort of (cooperative)
>multitasking that I'm thinking of.

I hope I'm not being too fussy, but seems to me that the CVar is what
is needed, not the MVar:

>main=
>  newCVar >>= \l0 ->
>  newCVar >>= \l1 ->
>  newCVar >>= \l2 ->
>  forkIO readInputLineAtATime l0 >>
>  forkIO printHeader "silly header" l0 l1 >>
>  forkIO numberLines 0 l1 l2 >>
>  printOutputLineAtATime l2

(untested code.)