precursor-0.1.0.0: Prelude replacement

Safe HaskellSafe
LanguageHaskell2010

Precursor.System.IO

Contents

Synopsis

The IO monad

data IO a :: * -> * #

A value of type IO a is a computation which, when performed, does some I/O before returning a value of type a.

There is really only one way to "perform" an I/O action: bind it to Main.main in your program. When your program is run, the I/O will be performed. It isn't possible to perform I/O from an arbitrary function, unless that function is itself in the IO monad and called at some point, directly or indirectly, from Main.main.

IO is a monad, so IO actions can be combined using either the do-notation or the >> and >>= operations from the Monad class.

Instances

Monad IO 

Methods

(>>=) :: IO a -> (a -> IO b) -> IO b #

(>>) :: IO a -> IO b -> IO b #

return :: a -> IO a #

fail :: String -> IO a #

Functor IO 

Methods

fmap :: (a -> b) -> IO a -> IO b #

(<$) :: a -> IO b -> IO a #

MonadFix IO 

Methods

mfix :: (a -> IO a) -> IO a #

Applicative IO 

Methods

pure :: a -> IO a #

(<*>) :: IO (a -> b) -> IO a -> IO b #

(*>) :: IO a -> IO b -> IO b #

(<*) :: IO a -> IO b -> IO a #

MonadIO IO 

Methods

liftIO :: IO a -> IO a #

Alternative IO 

Methods

empty :: IO a #

(<|>) :: IO a -> IO a -> IO a #

some :: IO a -> IO [a] #

many :: IO a -> IO [a] #

MonadPlus IO 

Methods

mzero :: IO a #

mplus :: IO a -> IO a -> IO a #

Quasi IO 
Monoid a => Monoid (IO a) 

Methods

mempty :: IO a #

mappend :: IO a -> IO a -> IO a #

mconcat :: [IO a] -> IO a #

IO class

class Monad m => MonadIO m where #

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

Minimal complete definition

liftIO

Methods

liftIO :: IO a -> m a #

Lift a computation from the IO monad.

Instances

MonadIO IO 

Methods

liftIO :: IO a -> IO a #

(Error e, MonadIO m) => MonadIO (ErrorT e m) 

Methods

liftIO :: IO a -> ErrorT e m a #

MonadIO m => MonadIO (StateT s m) 

Methods

liftIO :: IO a -> StateT s m a #

liftIO :: MonadIO m => forall a. IO a -> m a #

Lift a computation from the IO monad.

Files and handles

type FilePath = String #

File and directory names are values of type String, whose precise meaning is operating system dependent. Files can be opened, yielding a handle which can then be used to operate on the contents of that file.

File-at-a-time operations

readFile :: MonadIO m => FilePath -> m Text Source #

Read a file and return its contents as a string. The file is read lazily, as with getContents.

writeFile :: MonadIO m => FilePath -> Text -> m () Source #

Write a string to a file. The file is truncated to zero length before writing begins.

appendFile :: MonadIO m => FilePath -> Text -> m () Source #

Write a string the end of a file.

Special cases for standard input and output

interact :: MonadIO m => (Text -> Text) -> m () Source #

The interact function takes a function of type Text -> Text as its argument. The entire input from the standard input device is passed (lazily) to this function as its argument, and the resulting string is output on the standard output device.

getContents :: MonadIO m => m Text Source #

Lazily read all user input on stdin as a single string.

getLine :: MonadIO m => m Text Source #

Read a single line of user input from stdin.

putStr :: MonadIO m => Text -> m () Source #

Write a string to stdout.

putStrLn :: MonadIO m => Text -> m () Source #

Write a string to stdout, followed by a newline.