I am writing a partition method in Dafny as part of a quicksort implementation, and I want to specify that this method only modifies part of the backing array.
Here is the header for my method:
method partitionSegment (a : array<int>, first : int, len : int) returns (p : int)
modifies a
...
The idea is that the first and len parameters specify a segment of array a (elements a[first] ... a[first+len-1]); partitionSegment partitions this array, returning the index of the pivot, which will be between first and first+len-1.
In my modifies clause I would like to indicate that only a[first] ... a[first+len-1] can be modified, rather than all of a. However, when I try using a set comprehension such as:
method partitionSegment (a : array<int>, first : int, len : int) returns (p : int)
modifies (set x | first <= x < first+len :: a[x])
the type checker balks, saying this is a set of integers rather than a set of memory locations. (So a[x] is being interpreted as the value stored at a[x], and not the memory location a[x].)
Is there any way I can do this in dafny: specify part of an array in a modifies annotation?