monadIO- Overloading of concurrency variables

Copyright(c) 2010 Galois Inc.
LicenseBSD-style (see the file libraries/base/LICENSE)
MaintainerJohn Launchbury,
Safe HaskellNone



A low-tech concurrent interface to the console. When multiple threads want input, they send messages to the console with the format


The user supplies input to any requesting thread in a similar way:


At any time, the user can enter !! to obtain a listing of all the active prompts. Any input not of either of these forms is discarded.

example :: IO ()
example = setupStdinout processes

processes :: IO ()
processes = do
    forkIO $ (prompt "Enter something" >> return ())
    forkIO $ (prompt "Something else" >> return ())
    prompt "quit"      -- When the main thread dies,
    return ()          -- the whole interaction ends


setupStdInOut :: IO a -> IO a Source #

setupStdInOut establishes the context for prompt, by running a daemon while its argument is executing. The daemon is terminated once the argument to setupStdInOut finishes.

prompt :: HasFork io => String -> io String Source #

prompt is the main user level function of the module. The function prints its argument on stdout, prefixed by its process number. The user similarly selects the recipient by prefixing the process number, e.g. "23:". Active prompts will reprompt when !! is entered.

putStrLine :: MonadIO io => String -> io () Source #

putStrLine sends output to stdout, ensuring that lines are whole and uninterrupted (including the final newline).