I have a very simple Haskell file (HelloWorld.hs) that reads like this:<div><br></div><div><div>main = do</div><div> putStr "What's your name? "</div><div> n <- getLine</div><div> putStrLn $ "Pleased to meet you, " ++ n</div>
</div><div><br></div><div>When I load it into ghci, I get the following result, as expected:</div><div><br></div><div><div>[1 of 1] Compiling Main ( HelloWorld.hs, interpreted )</div><div>Ok, modules loaded: Main.</div>
<div>*Main> main</div><div>What's your name? Matt</div><div>Pleased to meet you, Matt</div><div>*Main> </div></div><div><br></div><div>However, when I compile the same file using ghc and run it in a terminal, I get a very different result:</div>
<div><br></div><div><div>matt@matt-Lenovo-G575:~/Haskell$ ghc HelloWorld.hs</div><div>[1 of 1] Compiling Main ( HelloWorld.hs, HelloWorld.o )</div><div>Linking HelloWorld ...</div><div>matt@matt-Lenovo-G575:~/Haskell$ ./HelloWorld</div>
<div>Matt</div><div>What's your name? Pleased to meet you, Matt</div><div>matt@matt-Lenovo-G575:~/Haskell$ </div></div><div><br></div><div><br></div><div>-- in other words, the getLine action is being run before the putStr action, for some strange reason.</div>
<div><br></div><div>Is this a bug? Can anyone enlighten me as to what might be going on?</div><div><br></div><div>Regards,</div><div><br></div><div>Matt.</div>