Copyright | (c) Michael Szvetits 2021 |
---|---|
License | BSD3 (see the file LICENSE) |
Maintainer | typedbyte@qualified.name |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Types and functions for handling mutable state in the environment of a
Program
.
Synopsis
- data State s = State {
- readState :: IO s
- writeState :: s -> IO ()
- get :: e `Has` State s => Program e s
- put :: e `Has` State s => s -> Program e ()
- modify :: e `Has` State s => (s -> s) -> Program e ()
- modify' :: e `Has` State s => (s -> s) -> Program e ()
- newState :: s -> IO (State s)
- modifyState :: State s -> (s -> s) -> IO ()
- modifyState' :: State s -> (s -> s) -> IO ()
State Effect
A record of functions which represents the operations on a mutable value.
State | |
|
Program-based State
modify :: e `Has` State s => (s -> s) -> Program e () Source #
Modifies the state, using the provided function.
IO-based State
newState :: s -> IO (State s) Source #
Creates a new record of functions for mutable state, backed by an IORef
.
modifyState :: State s -> (s -> s) -> IO () Source #
Modifies the state, using the provided function.
modifyState' :: State s -> (s -> s) -> IO () Source #
A strict version of modifyState
.