#lang scheme/load
(module inside scheme
(require (planet tov/affine-contracts:2:0))
(define ((adder x) y)
(let ([result (+ x y)])
(set! x 'symbol)
result))
(define-affine-box counter number?)
(define (new-counter)
(make-counter 0))
(define (next-counter b)
(let ([v (counter-ref b)])
(values v (make-counter (+ v 1)))))
(provide/contract
[adder (number? . -> . (number? . -o . number?))]
[new-counter (-> counter/c)]
[next-counter (counter/c . -> . (values number? counter/c))])
)
(require 'inside)
(define a (new-counter))
(define-values (b c) (next-counter a))
(define-values (d e) (next-counter c))
(define f (adder 3))
(define (bad1)
(next-counter a))
(define (bad2)
(next-counter c))
(define (bad-if-twice1)
(next-counter e))
(define (bad-if-twice2)
(f 4))