<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 09/02/11 15:34, Krzysztof Skrzętnicki wrote:
<blockquote
cite="mid:AANLkTikWsDP+Jo5i9fqs7dLqLOewZATs0bzBw_pYftzJ@mail.gmail.com"
type="cite">Hello Cafe,<br>
<br>
Here is a simple program that yields strange results:<br>
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">module Main
where</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">import
Control.Concurrent</span><br style="font-family: courier
new,monospace;">
<span style="font-family: courier new,monospace;">import
Control.Concurrent.Chan</span><br style="font-family: courier
new,monospace;">
<span style="font-family: courier new,monospace;">import
Control.Monad</span><br>
<br>
<span style="font-family: courier new,monospace;">main = do</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> c <- newChan</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writeChan c 1</span><br
style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> forkIO $
forever $ do</span><br style="font-family: courier
new,monospace;">
<span style="font-family: courier new,monospace;"> i <-
readChan c</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> print
("forkio",i)</span><br style="font-family: courier
new,monospace;">
<span style="font-family: courier new,monospace;">isEmptyChan c
>>= print</span><br style="font-family: courier
new,monospace;">
<br>
<br>
Now, this is strange thing: we put single element into the
channel. We take it out.<br>
</blockquote>
<br>
What your program does is put a single element into the channel, and
then *repeatedly* try to take one out (notice the forever you have
in there!). Judging by the results, the program deadlocks, which
seems like a reasonable outcome to me.<br>
<br>
Thanks,<br>
<br>
Neil.<br>
<br>
</body>
</html>