Concurrent Haskell (Ops...)

Andre W B Furtado [email protected]
Mon, 16 Apr 2001 23:55:11 -0300


This is a multi-part message in MIME format.

------=_NextPart_000_0005_01C0C6D0.AC857AE0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

[I mean "CONCURRENT Haskell" rather than "Haskell DIRECT" in the last =
email. Sorry.]

-------


I am trying to create a program that prints interleaved sequences of =
'a's and 'z's, using Haskell Direct (under GHC). I've tryied the =
following:

import Concurrent

main :: IO()
main =3D let loop ch =3D putStr(ch) >> loop ch in
       forkIO (loop "a") >> loop "z"

But this program prints only 'z's, and no 'a's. I was surprised by this, =
since GHC uses preemptive multitasking, not cooperative multitasking. =
Does anyone knows what's going wrong?

Thanks,
Andre W B Furtado

------=_NextPart_000_0005_01C0C6D0.AC857AE0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV style=3D"FONT: 10pt arial">
<DIV>[I mean "CONCURRENT Haskell" rather than "Haskell DIRECT" in the =
last=20
email. Sorry.]</DIV>
<DIV>&nbsp;</DIV>
<DIV>-------</DIV></DIV>
<DIV><BR></DIV>
<DIV><FONT face=3DArial size=3D2>I am trying to create a program that =
prints=20
interleaved sequences of&nbsp;'a's&nbsp;and 'z's, using Haskell Direct =
(under=20
GHC). I've tryied the following:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>import Concurrent</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>main :: IO()<BR>main =3D let loop ch =
=3D putStr(ch)=20
&gt;&gt; loop ch in<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; forkIO (loop =
"a")=20
&gt;&gt; loop "z"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>But this program prints only 'z's, and =
no=20
'a's.&nbsp;I was surprised by this, since GHC uses preemptive =
multitasking, not=20
cooperative multitasking. Does anyone knows what's going =
wrong?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Andre W&nbsp;B =
Furtado</FONT></DIV></BODY></HTML>

------=_NextPart_000_0005_01C0C6D0.AC857AE0--