Portability | multi parameter classes and functional depenedencies required |
---|---|

Stability | experimental |

Maintainer | Uwe Schmidt (uwe\@fh-wedel.de) |

Arrows for managing an explicit state

State arrows work similar to state monads. A state value is threaded through the application of arrows.

- class Arrow a => ArrowState s a | a -> s where
- changeState :: (s -> b -> s) -> a b b
- accessState :: (s -> b -> c) -> a b c
- getState :: a b s
- setState :: a s s
- nextState :: (s -> s) -> a b s

# Documentation

class Arrow a => ArrowState s a | a -> s whereSource

The interface for accessing and changing the state component.

Multi parameter classes and functional dependencies are required.

changeState :: (s -> b -> s) -> a b bSource

change the state of a state arrow by applying a function for computing a new state from the old and the arrow input. Result is the arrow input

accessState :: (s -> b -> c) -> a b cSource

access the state with a function using the arrow input as data for selecting state components.

read the complete state, ignore arrow input

definition: ` getState = accessState (\ s x -> s) `

overwrite the old state

definition: ` setState = changeState (\ s x -> x) `

nextState :: (s -> s) -> a b sSource

change state (and ignore input) and return new state

convenience function, usefull for generating e.g. unique identifiers:

example with SLA state list arrows

newId :: SLA Int b String newId = nextState (+1) >>> arr (('#':) . show) runSLA 0 (newId <+> newId <+> newId) undefined = ["#1", "#2", "#3"]

ArrowState s (SLA s) | |

ArrowState s (IOSLA s) |