Module "IOExts.curry"

Library with some useful extensions to the IO monad.

Author: Michael Hanus

Version: June 2007


 Exported names:

Datatypes:
IORef

Functions:
connectToCommand | exclusiveIO | execCmd | getAssoc | newIORef | readCompleteFile | readIORef | setAssoc | updateFile | writeIORef


 Summary of exported functions:

execCmd  :: String -> IO (Handle,Handle,Handle)  deterministic 
          Executes a command with a new default shell process.
connectToCommand  :: String -> IO Handle  deterministic 
          Executes a command with a new default shell process.
readCompleteFile  :: String -> IO String  deterministic 
          An action that reads the complete contents of a file and returns it.
updateFile  :: (String -> String) -> String -> IO ()  deterministic 
          An action that updates the contents of a file.
exclusiveIO  :: String -> IO a -> IO a  deterministic 
          Forces the exclusive execution of an action via a lock file.
setAssoc  :: String -> String -> IO ()  deterministic 
          Defines a global association between two strings.
getAssoc  :: String -> IO (Maybe String)  deterministic 
          Gets the value associated to a string.
newIORef  :: a -> IO (IORef a)  deterministic 
          Creates a new IORef with an initial values.
readIORef  :: IORef a -> IO a  deterministic 
          Reads the current value of an IORef.
writeIORef  :: IORef a -> a -> IO ()  deterministic 
          Updates the value of an IORef.

 Imported modules:

IO
Prelude
System

 Exported datatypes:

IORef

Mutable variables containing values of some type. The values are not evaluated when they are assigned to an IORef.

Constructors:



 Exported functions:

execCmd :: String -> IO (Handle,Handle,Handle)  deterministic 

Executes a command with a new default shell process. The standard I/O streams of the new process (stdin,stdout,stderr) are returned as handles so that they can be explicitly manipulated. They should be closed with IO.hClose since they are not closed automatically when the process terminates.

Example call:  (execCmd cmd)

Parameters:
cmd - the shell command to be executed
Returns:
the handles of the input/output/error streams of the new process

connectToCommand :: String -> IO Handle  deterministic 

Executes a command with a new default shell process. The input and output streams of the new process is returned as one handle which is both readable and writable. Thus, writing to the handle produces input to the process and output from the process can be retrieved by reading from this handle. The handle should be closed with IO.hClose since they are not closed automatically when the process terminates.

Example call:  (connectToCommand cmd)

Parameters:
cmd - the shell command to be executed
Returns:
the handle connected to the input/output streams of the new process

readCompleteFile :: String -> IO String  deterministic 

An action that reads the complete contents of a file and returns it. This action can be used instead of the (lazy) readFile action if the contents of the file might be changed.

Example call:  (readCompleteFile file)

Parameters:
file - the name of the file
Returns:
the complete contents of the file

updateFile :: (String -> String) -> String -> IO ()  deterministic 

An action that updates the contents of a file.

Example call:  (updateFile f file)

Parameters:
f - the function to transform the contents
file - the name of the file

exclusiveIO :: String -> IO a -> IO a  deterministic 

Forces the exclusive execution of an action via a lock file. For instance, (exclusiveIO "myaction.lock" act) ensures that the action "act" is not executed by two processes on the same system at the same time.

Example call:  (exclusiveIO lockfile action)

Parameters:
lockfile - the name of a global lock file
action - the action to be exclusively executed
Returns:
the result of the execution of the action

setAssoc :: String -> String -> IO ()  deterministic 

Defines a global association between two strings. Both arguments must be evaluable to ground terms before applying this operation.


getAssoc :: String -> IO (Maybe String)  deterministic 

Gets the value associated to a string. Nothing is returned if there does not exist an associated value.


newIORef :: a -> IO (IORef a)  deterministic 

Creates a new IORef with an initial values.

Further infos:
  • externally defined

readIORef :: IORef a -> IO a  deterministic 

Reads the current value of an IORef.


writeIORef :: IORef a -> a -> IO ()  deterministic 

Updates the value of an IORef.



Generated by CurryDoc (Version 0.4.1 of June 7, 2007) at Nov 9 18:02:59 2009