import System.IO

hangman :: IO ()
hangman = do putStrLn "Think of a word: "
             word <- secretlyGetLine
             play word

secretlyGetLine :: IO String
secretlyGetLine = do hSetEcho stdin False
                     xs <- getLine
                     putStrLn (replicate (length xs) '-')
                     hSetEcho stdin True
                     return xs

play :: String -> IO ()
play word = do putStr "What is your guess? "
               guess <- getLine
               if guess == word then
                 do putStr "Correct! The word was "
                    putStrLn word
               else
                 do putStrLn (match word guess)
                    play word

match :: String -> String -> String
match xs ys = [if x `elem` ys then x else '-'| x <- xs]

main = do hSetBuffering stdout NoBuffering
          hangman
