src/Pure/ML-Systems/unsynchronized.ML
author haftmann
Tue Oct 20 16:13:01 2009 +0200 (2009-10-20)
changeset 33037 b22e44496dc2
parent 32737 76fa673eee8b
child 38799 712cb964d113
permissions -rw-r--r--
replaced old_style infixes eq_set, subset, union, inter and variants by generic versions
     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;