[Haskell-beginners] Strange difference in behaviour between ghc and ghci

Arlen Cuss a at unnali.com
Thu Jun 7 13:28:53 CEST 2012


Hello! 

See this similar mailing list question from 2006:

http://www.haskell.org/pipermail/haskell/2006-September/018430.html

The short answer is that GHCi buffers differently, so you need to be more explicit about flushing.

HTH,

Arlen 


On Thursday, 7 June 2012 at 9:22 PM, Matthew Moppett wrote:

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






More information about the Beginners mailing list