Module
Control.Monad.Eff.Var
- Package
- purescript-var
- Repository
- zudov/purescript-var
Var
s allow to provide a uniform read/write access to the references in
the Eff
monad. This is mostly useful when making low-level FFI bindings.
For example we might have some global counter with the following API:
foreign import data COUNT :: !
getCounter :: forall eff. Eff (count :: COUNT | eff) Int
setCounter :: forall eff. Int -> Eff (count :: COUNT | eff) Unit
getCounter
and setCounter
can be kept together in a Var
:
counter :: forall eff. Var (count :: COUNT | eff) Int
counter = makeVar getCounter setCounter
counter
can be used in this way:
main = do
counter $= 0 -- set counter to 0
get counter >>= print -- => 0
counter $= 2 -- set counter to 2
get counter >>= print -- => 2
counter $~ (* 5) -- multiply counter by 5
get counter >>= print -- => 10
#($=) Source
Operator alias for Control.Monad.Eff.Var.set (right-associative / precedence 2)
Alias for set
.
#($~) Source
Operator alias for Control.Monad.Eff.Var.update (right-associative / precedence 2)
Alias for get
#GettableVar Source
newtype GettableVar eff a
Read-only var which holds a value of type a
and produces effects eff
when read.
Instances
Gettable eff (GettableVar eff) a
Functor (GettableVar eff)
Apply (GettableVar eff)
Applicative (GettableVar eff)
#makeGettableVar Source
makeGettableVar :: forall a eff. Eff eff a -> GettableVar eff a
Create a GettableVar
from getter.
#SettableVar Source
newtype SettableVar eff a
Write-only var which holds a value of type a
and produces effects eff
when written.
Instances
Settable eff (SettableVar eff) a
Contravariant (SettableVar eff)
Divide (SettableVar eff)
Divisible (SettableVar eff)
Decide (SettableVar eff)
Decidable (SettableVar eff)
#makeSettableVar Source
makeSettableVar :: forall a eff. (a -> Eff eff Unit) -> SettableVar eff a
Create a SettableVar
from setter.
- Modules
- Control.
Monad. Eff. Var