| 1 | (* Copyright (C) 2009 Matthew Fluet. |
| 2 | * Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh |
| 3 | * Jagannathan, and Stephen Weeks. |
| 4 | * |
| 5 | * MLton is released under a BSD-style license. |
| 6 | * See the file MLton-LICENSE for details. |
| 7 | *) |
| 8 | |
| 9 | structure Counter: COUNTER = |
| 10 | struct |
| 11 | |
| 12 | datatype t = T of int ref |
| 13 | |
| 14 | fun new n = T(ref n) |
| 15 | |
| 16 | fun reset(T r, n) = r := n |
| 17 | |
| 18 | fun tick(T r) = Int.inc r |
| 19 | |
| 20 | fun value(T r) = !r |
| 21 | |
| 22 | fun next c = value c before tick c |
| 23 | |
| 24 | val equals = fn (T r, T r') => r = r' |
| 25 | |
| 26 | end |