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>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?</div>
<div>h</div><div>104</div><div>You win!</div><div>What&#39;s your guess, heads or tails (&#39;h&#39; or &#39;t&#39;)?</div><div><b>10</b></div><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>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">On Mon, Oct 12, 2009 at 12:10 AM, michael rice <span dir="ltr">&lt;<a href="mailto:nowgate@yahoo.com">nowgate@yahoo.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><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>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">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>