32737
|
1 |
(* Title: Pure/ML-Systems/unsynchronized.ML
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Raw ML references as unsynchronized state variables.
|
|
5 |
*)
|
|
6 |
|
|
7 |
structure Unsynchronized =
|
|
8 |
struct
|
|
9 |
|
|
10 |
datatype ref = datatype ref;
|
|
11 |
|
|
12 |
val op := = op :=;
|
|
13 |
val ! = !;
|
|
14 |
|
|
15 |
fun set flag = (flag := true; true);
|
|
16 |
fun reset flag = (flag := false; false);
|
|
17 |
fun toggle flag = (flag := not (! flag); ! flag);
|
|
18 |
|
|
19 |
fun change r f = r := f (! r);
|
|
20 |
fun change_result r f = let val (x, y) = f (! r) in r := y; x end;
|
|
21 |
|
|
22 |
fun inc i = (i := ! i + (1: int); ! i);
|
|
23 |
fun dec i = (i := ! i - (1: int); ! i);
|
|
24 |
|
|
25 |
end;
|