|
4 | 4 | -- | _Note_: The `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.Eff.Ref where |
| 7 | +module Control.Monad.Effect.Ref where |
8 | 8 |
|
| 9 | +import Control.Monad.Effect (Effect) |
9 | 10 | import Prelude (Unit, unit) |
10 | | -import Control.Monad.Eff (Eff, kind Effect) |
11 | | - |
12 | | --- | The effect associated with the use of global mutable variables. |
13 | | -foreign import data REF :: Effect |
14 | 11 |
|
15 | 12 | -- | A value of type `Ref a` represents a mutable reference |
16 | 13 | -- | which holds a value of type `a`. |
17 | 14 | foreign import data Ref :: Type -> Type |
18 | 15 |
|
19 | 16 | -- | Create a new mutable reference containing the specified value. |
20 | | -foreign import newRef :: forall s r. s -> Eff (ref :: REF | r) (Ref s) |
| 17 | +foreign import newRef :: forall s. s -> Effect (Ref s) |
21 | 18 |
|
22 | 19 | -- | Read the current value of a mutable reference |
23 | | -foreign import readRef :: forall s r. Ref s -> Eff (ref :: REF | r) s |
| 20 | +foreign import readRef :: forall s. Ref s -> Effect s |
24 | 21 |
|
25 | 22 | -- | Update the value of a mutable reference by applying a function |
26 | 23 | -- | to the current value. |
27 | | -foreign import modifyRef' :: forall s b r. Ref s -> (s -> { state :: s, value :: b }) -> Eff (ref :: REF | r) b |
| 24 | +foreign import modifyRef' :: forall s b. Ref s -> (s -> { state :: s, value :: b }) -> Effect b |
28 | 25 |
|
29 | 26 | -- | Update the value of a mutable reference by applying a function |
30 | 27 | -- | to the current value. |
31 | | -modifyRef :: forall s r. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit |
| 28 | +modifyRef :: forall s. Ref s -> (s -> s) -> Effect Unit |
32 | 29 | modifyRef ref f = modifyRef' ref (\s -> { state: f s, value: unit }) |
33 | 30 |
|
34 | 31 | -- | Update the value of a mutable reference to the specified value. |
35 | | -foreign import writeRef :: forall s r. Ref s -> s -> Eff (ref :: REF | r) Unit |
| 32 | +foreign import writeRef :: forall s. Ref s -> s -> Effect Unit |
0 commit comments