Skip to content

Instantly share code, notes, and snippets.

@vlad-shatskyi
Created February 27, 2015 21:47
Show Gist options
  • Save vlad-shatskyi/b40fbb2b6bc574a1b459 to your computer and use it in GitHub Desktop.
Save vlad-shatskyi/b40fbb2b6bc574a1b459 to your computer and use it in GitHub Desktop.
module Main where
import System.Environment
import System.IO (hFlush, stdout)
ask :: (Show a, Read b) => a -> IO b
ask question = do
putStr $ show question
hFlush stdout
answer <- getLine
read answer
main :: IO ()
main = do
name <- ask "What's your name, stranger? "
print $ "Welcome home, " ++ name
@vlad-shatskyi
Copy link
Author

    Could not deduce (Read (IO b)) arising from a use of ‘read’
    from the context (Show a, Read b)
      bound by the type signature for
                 ask :: (Show a, Read b) => a -> IO b
      at listing.hs:6:8-36
    In a stmt of a 'do' block: read answer
    In the expression:
      do { putStr $ show question;
           hFlush stdout;
           answer <- getLine;
           read answer }
    In an equation for ‘ask’:
        ask question
          = do { putStr $ show question;
                 hFlush stdout;
                 answer <- getLine;
                 .... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment