printing menu in terminal and choosing an option, how to?
Posted
by
carlos
on Stack Overflow
See other posts from Stack Overflow
or by carlos
Published on 2012-12-13T22:55:42Z
Indexed on
2012/12/13
23:03 UTC
Read the original article
Hit count: 230
I'm a haskell beginner.
I'm trying to make a program that shows a menu through terminal and ask user to introduce an option. Here is the code:
main :: IO ()
main = do
putStrLn "0 <- quit"
putStrLn "1 <- Hello"
putStr "Choose an option: "
c <- getChar
case c of
'0' -> return ()
'1' -> putChar '\n' >> putStrLn "Hello World" >> main
When I use this module in the ghci interpreter everything works like it's suposed to do. But if i compile this with:
ghc hello.hs
and run it in the terminal, it doesn't display the line "Choose an option:" before ask for a char to be introduced. I think this may be caused because of haskell lazy nature and I don't know how to fix it.
Any ideas?
© Stack Overflow or respective owner