Skip to content

Instantly share code, notes, and snippets.

@vlad-shatskyi

vlad-shatskyi/ask

Created Feb 27, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@vlad-shatskyi vlad-shatskyi commented Feb 27, 2015

    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