precursor-0.1.0.0: Prelude replacement

Precursor.System.IO

Synopsis

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

 Methods(>>=) :: IO a -> (a -> IO b) -> IO b #(>>) :: IO a -> IO b -> IO b #return :: a -> IO a #fail :: String -> IO a # Methodsfmap :: (a -> b) -> IO a -> IO b #(<\$) :: a -> IO b -> IO a # Methodsmfix :: (a -> IO a) -> IO a # Methodspure :: a -> IO a #(<*>) :: IO (a -> b) -> IO a -> IO b #(*>) :: IO a -> IO b -> IO b #(<*) :: IO a -> IO b -> IO a # MethodsliftIO :: IO a -> IO a # Methodsempty :: IO a #(<|>) :: IO a -> IO a -> IO a #some :: IO a -> IO [a] #many :: IO a -> IO [a] # Methodsmzero :: IO a #mplus :: IO a -> IO a -> IO a # MethodsqReport :: Bool -> String -> IO () #qRecover :: IO a -> IO a -> IO a #qReifyInstances :: Name -> [Type] -> IO [Dec] #qReifyRoles :: Name -> IO [Role] #qReifyAnnotations :: Data a => AnnLookup -> IO [a] #qRunIO :: IO a -> IO a #qAddTopDecls :: [Dec] -> IO () #qAddModFinalizer :: Q () -> IO () #qGetQ :: Typeable * a => IO (Maybe a) #qPutQ :: Typeable * a => a -> IO () # Monoid a => Monoid (IO a) Methodsmempty :: IO a #mappend :: IO a -> IO a -> IO a #mconcat :: [IO a] -> IO a #

# IO class

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:

• liftIO . return = return
• liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Minimal complete definition

liftIO

Methods

liftIO :: IO a -> m a #

Lift a computation from the IO monad.

Instances

 MethodsliftIO :: IO a -> IO a # (Error e, MonadIO m) => MonadIO (ErrorT e m) MethodsliftIO :: IO a -> ErrorT e m a # MonadIO m => MonadIO (StateT s m) MethodsliftIO :: 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

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.