//  A callback type whose `@Global` states what the subprograms it designates may use: a call
//  through it reads and writes Count as a call of Bump would
package Counters {
    pub var Count: Natural = 0;

    pub type Action = not null *fn(Step: Natural)
        @Global(In_Out => Count)
        @Post(Count >= old(Count));

    pub fn Bump(Step: Natural)
        @Global(In_Out => Count)
        ensures Count >= old(Count)
    {
        if Count <= 1000 && Step <= 10 {
            Count += Step;
        }
    }

    pub fn Apply(A: Action, Step: Natural) @Global(In_Out => Count) {
        let Before: Natural = Count;
        A(Step);
        assert Count >= Before;
    }
}
