[Haskell-cafe] ghc --make Vs runhaskell
madhub.bits at gmail.com
Wed Feb 4 03:23:42 UTC 2015
I have the following program from “Learn You a Haskell” (
http://learnyouahaskell.com/input-and-output#randomness ). When i run this
using runhaskell, code works perfectly fine. However, when i compile and
run the binary file, code behaves differently.
Basically, in the following code, we print a line first and the read the
line from stdin. This behavior works perfectly fine when using “runhaskell
guess.hs”. But when i say “./guess”, i had to type in a number directly (
i.e. first prompt is skipped ).
btw.. i am using mac yosomite command terminal.
Any help greatly appreciated.. Thanks a lot in advance..
main = do
ranGen <- getStdGen
let (rand,_) = randomR (1,10) ranGen :: (Int,StdGen)
putStr "Guess a number between 1 and 10 : "
numStr <- getLine
when(not $ null numStr) $ do
let num = read numStr
if rand == num
then putStrLn "Yuhaa!! you are right baby!"
else putStrLn $ "Sorry dude!! it was " ++ show rand
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe