<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The issue you're hitting I believe is two fold:<div><br></div><div>1) stdin has line buffering turned on. &nbsp;This means that the first example does not run until return is pressed because the input is not sent to ghci until then.</div><div>2) You now have a 3rd character on stdin that's yet to be consumed – a new line character, this causes getTwoChars to grab that, and the following character when it's run a second time.</div><div><br></div><div>You could solve this by turning off buffering on stdin, or by making getTwoChars ignore new lines.</div><div><br></div><div>Bob<br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div><span class="Apple-style-span" style="font-family: Arial; "><pre>if (*ra4 != 0xffc78948) { return false; }</pre></span></div></span>
</div>
<br><div><div>On 27 Oct 2011, at 15:48, Rustom Mody wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">I have this from Peyton Jones awkward squad paper<br><br>getTwoChars :: IO (Char,Char)<br>getTwoChars = do <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c1 &lt;- getChar<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c2 &lt;- getChar<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (c1,c2)<br><br>Can someone explain what is happening here?<br>
*Main&gt; getTwoChars<br>ab<br>('a','b')<br>*Main&gt; getTwoChars<br>a<br>('\n','a')<br>
_______________________________________________<br>Beginners mailing list<br><a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>http://www.haskell.org/mailman/listinfo/beginners<br></blockquote></div><br></div></body></html>