hxt-filter-8.4.2: A collection of tools for processing XML with Haskell (Filter variant).

Control.Monad.MonadStateIO

Description

general usefull state monad for a local state and IO

This module is used for threading a state and io actions through a computation. Here the monad is constructed by hand. It could easily be refactored with the use of the monad transformer library.

Synopsis

Documentation

newtype StateIO state res Source

Constructors

STIO 

Fields

trans :: state -> IO (res, state)
 

Instances

Monad (StateIO state) 

io :: IO a -> StateIO state aSource

lift IO command to StateIO

trcState :: (state -> String) -> StateIO state ()Source

state inspection command: a "show"-like function is applied to the state and the result is written to stderr.

changeState :: (state -> state) -> StateIO state stateSource

change the state with a given function and return the new state

setState :: state -> StateIO state stateSource

set the state

getState :: StateIO state stateSource

read the state

run :: state -> StateIO state res -> IO resSource

run a StateIO command with an initial state