|
1 | 1 | -- | This module defines an effect and actions for working with |
2 | 2 | -- | global mutable variables. |
3 | 3 | -- | |
4 | | --- | _Note_: The `Control.Monad.ST` provides a _safe_ alternative |
| 4 | +-- | _Note_: `Control.Monad.ST` provides a _safe_ alternative |
5 | 5 | -- | to global mutable variables when mutation is restricted to a |
6 | 6 | -- | local scope. |
7 | | -module Control.Monad.Effect.Ref where |
| 7 | +module Effect.Ref where |
8 | 8 |
|
9 | | -import Control.Monad.Effect (Effect) |
10 | | -import Prelude (Unit, unit) |
| 9 | +import Prelude |
| 10 | + |
| 11 | +import Effect (Effect) |
11 | 12 |
|
12 | 13 | -- | A value of type `Ref a` represents a mutable reference |
13 | 14 | -- | which holds a value of type `a`. |
14 | 15 | foreign import data Ref :: Type -> Type |
15 | 16 |
|
16 | 17 | -- | Create a new mutable reference containing the specified value. |
17 | | -foreign import newRef :: forall s. s -> Effect (Ref s) |
| 18 | +foreign import new :: forall s. s -> Effect (Ref s) |
18 | 19 |
|
19 | 20 | -- | Read the current value of a mutable reference |
20 | | -foreign import readRef :: forall s. Ref s -> Effect s |
| 21 | +foreign import read :: forall s. Ref s -> Effect s |
21 | 22 |
|
22 | 23 | -- | Update the value of a mutable reference by applying a function |
23 | 24 | -- | to the current value. |
24 | | -foreign import modifyRef' :: forall s b. Ref s -> (s -> { state :: s, value :: b }) -> Effect b |
| 25 | +foreign import modify' :: forall s b. (s -> { state :: s, value :: b }) -> Ref s -> Effect b |
25 | 26 |
|
26 | 27 | -- | Update the value of a mutable reference by applying a function |
27 | 28 | -- | to the current value. |
28 | | -modifyRef :: forall s. Ref s -> (s -> s) -> Effect Unit |
29 | | -modifyRef ref f = modifyRef' ref (\s -> { state: f s, value: unit }) |
| 29 | +modify :: forall s. (s -> s) -> Ref s -> Effect Unit |
| 30 | +modify f = modify' (\s -> { state: f s, value: unit }) |
30 | 31 |
|
31 | 32 | -- | Update the value of a mutable reference to the specified value. |
32 | | -foreign import writeRef :: forall s. Ref s -> s -> Effect Unit |
| 33 | +foreign import write :: forall s. s -> Ref s -> Effect Unit |
0 commit comments