[Haskell-cafe] ghc --make Vs runhaskell
Madhu Babu
madhub.bits at gmail.com
Wed Feb 4 03:23:42 UTC 2015
Hi !,
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..
import System.Random
import Control.Monad(when)
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
newStdGen
main
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20150203/28dfa686/attachment.html>
More information about the Haskell-Cafe
mailing list