Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data State s (e :: Effects)
- evalState :: forall s (es :: Effects) a. s -> (forall (e :: Effects). State s e -> Eff (e :& es) a) -> Eff es a
- runState :: forall s (es :: Effects) a. s -> (forall (e :: Effects). State s e -> Eff (e :& es) a) -> Eff es (a, s)
- withState :: forall s (es :: Effects) a. s -> (forall (e :: Effects). State s e -> Eff (e :& es) (s -> a)) -> Eff es a
- get :: forall (e :: Effects) (es :: Effects) s. e :> es => State s e -> Eff es s
- put :: forall (e :: Effects) (es :: Effects) s. e :> es => State s e -> s -> Eff es ()
- modify :: forall (e :: Effects) (es :: Effects) s. e :> es => State s e -> (s -> s) -> Eff es ()
Handle
A handle to a strict mutable state of type s
Handlers
:: forall s (es :: Effects) a. s | Initial state |
-> (forall (e :: Effects). State s e -> Eff (e :& 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 (e :: Effects). State s e -> Eff (e :& 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)
:: forall s (es :: Effects) a. s | Initial state |
-> (forall (e :: Effects). State s e -> Eff (e :& es) (s -> a)) | Stateful computation |
-> Eff es a | Result |
>>> runPureEff $ withState 10 $ \st -> do n <- get st pure (s -> (2 * n, s)) (20,10)
Effectful operations
:: forall (e :: Effects) (es :: Effects) s. e :> es | |
=> State s e | |
-> Eff es s | The current value of the state |
>>> runPureEff $ runState 10 $ \st -> do n <- get st pure (2 * n) (20,10)