Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data State s (st :: Effects)
- evalState :: forall s (es :: Effects) a. s -> (forall (st :: Effects). State s st -> Eff (st :& es) a) -> Eff es a
- runState :: forall s (es :: Effects) a. s -> (forall (st :: Effects). State s st -> Eff (st :& es) a) -> Eff es (a, s)
- get :: forall (st :: Effects) (es :: Effects) s. st :> es => State s st -> Eff es s
- put :: forall (st :: Effects) (es :: Effects) s. st :> es => State s st -> s -> Eff es ()
- modify :: forall (st :: Effects) (es :: Effects) s. st :> es => State s st -> (s -> s) -> Eff es ()
Handle
Handlers
:: forall s (es :: Effects) a. s | Initial state |
-> (forall (st :: Effects). State s st -> Eff (st :& es) a) | Stateful computation |
-> Eff es a | Result |
>>> runPureEff $ evalState 10 $ \st -> do n <- get st pure (2 * n) 20
:: forall s (es :: Effects) a. s | Initial state |
-> (forall (st :: Effects). State s st -> Eff (st :& es) a) | Stateful computation |
-> Eff es (a, s) | Result and final state |
>>> runPureEff $ runState 10 $ \st -> do n <- get st pure (2 * n) (20,10)
Effectful operations
:: forall (st :: Effects) (es :: Effects) s. st :> es | |
=> State s st | |
-> Eff es s | The current value of the state |
>>> runPureEff $ runState 10 $ \st -> do n <- get st pure (2 * n) (20,10)