Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell beginner help

Name: Anonymous 2009-02-25 16:03

I'm learning haskell and I stumbled upon a problem. Here's the code:

module Main
  where

main = do putStr "Input your name: "
          s <- getLine
          putStrLn s
          main


But after compiling and running, the prompt string doesn't get printed until I input stuff, like this:

foo
Input your name: foo
bar
Input your name: bar


When running the code in the interpreter, everything's alright. What's the problem?

Name: Anonymous 2009-02-25 16:34

Okay, one more thing. I want the program to stop when :q is entered. I wanted to do it like this:

main = do putStr "Input your name: "
          hFlush stdout
          s <- getLine
          putStrLn s
          if (s /= ":q") then main


But it doesn't work. How should I do that?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List