btw I always find it amusing to play with interact and lazy IO:<div><br></div><div><div>guess :: [Char] -&gt; [String] -&gt; [String]</div><div>guess (c:cs) ~(i:is) = </div><div>  &quot;What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?&quot; : </div>
<div>  (if [c]==i then &quot;You win!&quot; else &quot;You lose!&quot;) :</div><div>  guess cs is </div><div><br></div><div>main = do</div><div>  gen &lt;- getStdGen</div><div>  let rs = randomRs  (0,1::Int) gen</div><div>
      cs = map (&quot;ht&quot;!!) rs</div><div>  interact $ unlines . guess cs . lines</div><div><br></div><div><br></div><br><div class="gmail_quote">On Mon, Oct 12, 2009 at 12:24 AM, Peter Verswyvelen <span dir="ltr">&lt;<a href="mailto:bugfact@gmail.com">bugfact@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">It always helps to put a Debug.Trace.trace:<div><br></div><div>                    in if trace (show (fromEnum c)) $ c == ((!!) &quot;ht&quot; randInt) then p</div>
<div><br></div><div><div class="im"><div>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?</div>
<div>h</div></div><div>104</div><div class="im"><div>You win!</div><div>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?</div></div><div><b>10</b></div><div class="im"><div>You lose!</div><div>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?</div>

<div><br></div></div><div>So getChar also receives the linefeed character.</div><div><br></div><div>An easy way to get around this, is to use getLine instead and just use the first character, as in</div><div><br></div><div>
<div>
               &gt;&gt; fmap head getLine </div><div><br></div><div>But of course we&#39;re hacking away here :-)<br></div><div><br></div></div><div class="gmail_quote"><div><div></div><div class="h5">On Mon, Oct 12, 2009 at 12:10 AM, michael rice <span dir="ltr">&lt;<a href="mailto:nowgate@yahoo.com" target="_blank">nowgate@yahoo.com</a>&gt;</span> wrote:<br>

</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">
What is going wrong here?<br>
<br>Michael<br><br>=======<br><br>import System.Random<br><br>coinToss :: StdGen -&gt; IO ()<br>coinToss gen = putStrLn &quot;What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?&quot;<br>               &gt;&gt; getChar<br>

               &gt;&gt;= \c -&gt; let (randInt, _) = randomR(0,1) gen :: (Int, StdGen)<br>                    in if c == ((!!) &quot;ht&quot; randInt) then putStrLn &quot;You win!&quot; else putStrLn &quot;You lose!&quot;<br>

<br>main = do<br>         gen &lt;- getStdGen<br>         coinToss gen<br>         gen
 &lt;- newStdGen<br>         main<br><br>=======<br><br>[michael@localhost ~]$ runhaskell cointoss.hs<br>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?<br>h<br>You win!<br>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?<br>

You lose!<br>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?<br>h<br>You lose!<br>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?<br>You lose!<br>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?<br>

^Ccointoss.hs: cointoss.hs: interrupted<br>[michael@localhost ~]$ <br><br></td></tr></tbody></table><br>



      <br></div></div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>