HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulehxt-9.3.1.22Haskell2010

Control.Arrow.ArrowState

Arrows for managing an explicit state

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

  • 1 class
  • Packagehxt-9.3.1.22
  • Exports1
  • LanguageHaskell2010
  • LicenceMIT
  • SourceArrowState.hs
classclass Arrow a => ArrowState s (a :: Type -> Type -> Type) | a -> s where
#

The interface for accessing and changing the state component.

Multi parameter classes and functional dependencies are required.

Methods

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

    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 c

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

  • getState :: a b s

    read the complete state, ignore arrow input

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

  • setState :: a s s

    overwrite the old state

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

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

    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"]
Instances2ArrowState
  • ArrowState s (IOSLA s)Defined in hxt-9.3.1.22 · Control.Arrow.IOStateListArrow
  • ArrowState s (SLA s)Defined in hxt-9.3.1.22 · Control.Arrow.StateListArrow