OK -- thanks everybody for your enlightening responses.<div><br></div><div>Regards,</div><div><br></div><div>Matt.<br><br><div class="gmail_quote">On Thu, Jun 7, 2012 at 9:40 PM, Henry Lockyer <span dir="ltr"><<a href="mailto:henry.lockyer@ntlworld.com" target="_blank">henry.lockyer@ntlworld.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">in other words, in your version "What's your name?" *has* been put in the IO output buffer but this has not been flushed<br>
to the terminal yet. You then input your name (without having seen the prompt you were expecting (yet)) and then<br>
the newline of your subsequent putStrLn flushes both bits of output at the same time.<br>
<div class="HOEnZb"><div class="h5"><br>
On 7 Jun 2012, at 12:32, Henry Lockyer wrote:<br>
<br>
> A very quick reply and without reading carefully considering what may be different in GHCI (!),<br>
> but the output buffer flushes (at least on my system) with newline (if you don;t flush it 'manually').<br>
> I suspect if you use putStrLn for 'what's your name' you may get something more like what you want.<br>
><br>
><br>
> On 7 Jun 2012, at 12:22, Matthew Moppett wrote:<br>
><br>
>> I have a very simple Haskell file (HelloWorld.hs) that reads like this:<br>
>><br>
>> main = do<br>
>> putStr "What's your name? "<br>
>> n <- getLine<br>
>> putStrLn $ "Pleased to meet you, " ++ n<br>
>><br>
>> When I load it into ghci, I get the following result, as expected:<br>
>><br>
>> [1 of 1] Compiling Main ( HelloWorld.hs, interpreted )<br>
>> Ok, modules loaded: Main.<br>
>> *Main> main<br>
>> What's your name? Matt<br>
>> Pleased to meet you, Matt<br>
>> *Main><br>
>><br>
>> However, when I compile the same file using ghc and run it in a terminal, I get a very different result:<br>
>><br>
>> matt@matt-Lenovo-G575:~/Haskell$ ghc HelloWorld.hs<br>
>> [1 of 1] Compiling Main ( HelloWorld.hs, HelloWorld.o )<br>
>> Linking HelloWorld ...<br>
>> matt@matt-Lenovo-G575:~/Haskell$ ./HelloWorld<br>
>> Matt<br>
>> What's your name? Pleased to meet you, Matt<br>
>> matt@matt-Lenovo-G575:~/Haskell$<br>
>><br>
>><br>
>> -- in other words, the getLine action is being run before the putStr action, for some strange reason.<br>
>><br>
>> Is this a bug? Can anyone enlighten me as to what might be going on?<br>
>><br>
>> Regards,<br>
>><br>
>> Matt.<br>
>> _______________________________________________<br>
>> Beginners mailing list<br>
>> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
>> <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
><br>
><br>
> _______________________________________________<br>
> Beginners mailing list<br>
> <a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/beginners" target="_blank">http://www.haskell.org/mailman/listinfo/beginners</a><br>
<br>
</div></div></blockquote></div><br></div>