If you redefine as follows:<br><br>server :: [Integer] -&gt; Writer [String] [Integer]<br>server [] = return []<br>server (a:as) = do<br>  tell [&quot;Server &quot; ++ show a]<br>  rs &lt;- server as<br>  return (a:rs)<br>
<br>You get this for the output:<br><br><br>[&quot;Server 0&quot;,&quot;Server 1&quot;,&quot;Server 2&quot;,&quot;Server 3&quot;,&quot;Server 4&quot;,&quot;Server 5&quot;,&quot;Server 6&quot;,&quot;Server 7&quot;,&quot;Server 8&quot;,&quot;Server 9&quot;,&quot;Server 1
<br>0&quot;,&quot;Client 0&quot;,&quot;Client 1&quot;,&quot;Client 2&quot;,&quot;Client 3&quot;,&quot;Client 4&quot;,&quot;Client 5&quot;,&quot;Client 6&quot;,&quot;Client 7&quot;,&quot;Client 8&quot;,&quot;Client 9&quot;]
<br><br>Then you just need to alternate the pattern. &nbsp;Though  a real simulation of&nbsp;sever&nbsp;traffic would&nbsp;account&nbsp;for&nbsp;the&nbsp;packets&nbsp;<br>not&nbsp;being&nbsp;recieved, rerequested, or recieved out of order. &nbsp;It also depends whether you are simulating TCP or UDP.
<br><br><div><span class="gmail_quote">On 1/14/08, <b class="gmail_sendername">Jan Stranik</b> &lt;<a href="mailto:janstranik@yahoo.de">janstranik@yahoo.de</a>&gt; wrote:</span><blockquote class="gmail_quote" style="margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; margin-left: 0.80ex; border-left-color: #cccccc; border-left-width: 1px; border-left-style: solid; padding-left: 1ex">
<div lang="EN-US" link="#0000ff" vlink="#800080"><div><p>Hello,</p><p>I am trying to simulate a client server traffic using recursive lazy evaluation. I am trying to do that in a recursive writer monad. </p><p>Following code is my attempt to simulate client server interaction and collect its transcript:
</p><p style="margin-left: 0.50in">{-# OPTIONS -fglasgow-exts #-}</p><p style="margin-left: 0.50in">module Main where</p><p style="margin-left: 0.50in">&nbsp;</p><p style="margin-left: 0.50in">import Control.Monad.Writer.Lazy</p>
<p style="margin-left: 0.50in">simulation:: Writer [String] ()</p><p style="margin-left: 0.50in">simulation = mdo</p><p style="margin-left: 0.50in">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a &lt;- server cr</p><p style="margin-left: 0.50in">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cr &lt;- client $ take 10 a
</p><p style="margin-left: 0.50in">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ()</p><p style="margin-left: 0.50in">&nbsp;</p><p style="margin-left: 0.50in">server:: [Integer] -&gt; Writer [String] [Integer]</p><p style="margin-left: 0.50in">server (a:as) = do
</p><p style="margin-left: 0.50in">&nbsp; tell [&quot;server &quot; ++ show a]</p><p style="margin-left: 0.50in">&nbsp; rs &lt;- server as</p><p style="margin-left: 0.50in">&nbsp; return ((a*2):rs)</p><p style="margin-left: 0.50in">&nbsp;</p>
<p style="margin-left: 0.50in">server [] = return []</p><p style="margin-left: 0.50in">&nbsp;</p><p style="margin-left: 0.50in">client:: [Integer] -&gt; Writer [String] [Integer]</p><p style="margin-left: 0.50in">client as = do
</p><p style="margin-left: 0.50in">&nbsp; dc &lt;- doClient as</p><p style="margin-left: 0.50in">&nbsp; return (0:dc)</p><p style="margin-left: 0.50in">&nbsp;&nbsp;&nbsp; where </p><p style="margin-left: 0.50in">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doClient (a:as) = do</p><p style="margin-left: 0.50in">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tell [&quot;Client &quot; ++ show a]</p><p style="margin-left: 0.50in">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; as&#39; &lt;- doClient as</p><p style="margin-left: 0.50in">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ((a+1):as&#39;)</p><p style="margin-left: 0.50in">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; doClient [] = return []</p><p style="margin-left: 0.50in">&nbsp;</p><p style="margin-left: 0.50in">main = return $ snd $ runWriter simulation</p><p>&nbsp;</p><p>The problem that I see is that the transcript collected contains first all output from the server, and then output from the client.
</p><p>Here is an example of output that I see: </p><p>:[&quot;server 0&quot;,&quot;server 1&quot;,&quot;server 3&quot;,&quot;server 7&quot;,&quot;server 15&quot;,&quot;server 31&quot;,&quot;server 63&quot;,&quot;server 127&quot;,&quot;server 255&quot;,&quot;server 511&quot;,&quot;server 1023&quot;,&quot;Client 0&quot;,&quot;Client 2&quot;,&quot;Client 6&quot;,&quot;Client 14&quot;,&quot;Client 30&quot;,&quot;Client 62&quot;,&quot;Client 126&quot;,&quot;Client 254&quot;,&quot;Client 510&quot;,&quot;Client 1022&quot;]
</p><p>&nbsp;</p><p>I would like to collect the output like:</p><p>:[&quot;client 0&quot;,&quot;server 0", "client 1",…]</p><p>&nbsp;</p><p>This would allow me to remove the ending condition in simulation (take 10), and instead rely fully on lazy evaluation to collect as many simulation steps as needed by my computation. &nbsp;
</p><p>I am still relatively new to the concepts of recursive monadic computations, so I would appreciate any suggestions from experts on this mailing list. </p><p>&nbsp;</p><p>Thank you</p><p>&nbsp;</p><p>Jan</p><p>&nbsp;</p></div></div>
<br>_______________________________________________<br>Haskell mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:Haskell@haskell.org">Haskell@haskell.org</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.haskell.org/mailman/listinfo/haskell" target="_blank">
http://www.haskell.org/mailman/listinfo/haskell</a><br><br></blockquote></div><br>