Safe Haskell | None |
---|
PureIO
Description
Pure IO monad, intended for educational use.
- runIO :: Input -> IO a -> (Either Interrupt a, Output)
- data IO a
- data Input = Input {
- inputStdin :: ![String]
- data Output = Output {
- outputStdout :: ![String]
- data Interrupt
- data IOException = UserError String
- putStrLn :: String -> IO ()
- putStr :: String -> IO ()
- getLine :: IO String
- readLn :: Read a => IO a
- print :: Show a => a -> IO ()
- readIO :: Read a => String -> IO a
- throw :: IOException -> IO a
The IO monad and its machinery
runIO :: Input -> IO a -> (Either Interrupt a, Output)Source
Run the IO monad. This should be called in succession. Depending on the type of interrupt, this function should be re-run with the same action but with additional input.
IO monad output.
Constructors
Output | |
Fields
|
Something that interrupts the flow of the IO monad.
Constructors
InterruptStdin | When you receive this interrupt, you should
get some standard input from somewhere and then
provide it in the |
InterruptException !IOException | When you receive this interrupt, you should consider the computation as ended. |
Library of actions
print :: Show a => a -> IO ()Source
The print
function outputs a value of any printable type to the
standard output device.
Printable types are those that are instances of class Show
; print
converts values to strings for output using the show
operation and
adds a newline.
For example, a program to print the first 20 integers and their powers of 2 could be written as:
main = print ([(n, 2^n) | n <- [0..19]])
throw :: IOException -> IO aSource
Throw an IO exception.