Support for strings/bytes and extending Seq #132
edwintorok
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I think it would be useful for Gospel (or its stdlib) to include support for strings. It is quite hard to avoid using strings in some form in a module, and some basic support in the stdlib for it would be useful.
It might be possible to write the Bytes interface using the existing Gospel syntax and stdlib, but not everything is easily definable.
Going through the exercise of providing a spec for something like Bytes or Buffer would be a useful way to enhance the expresiveness of Seq.
See below for my attempt on getting started on this. Would it be useful if I continue this and present a fully specced Bytes and Buffer interface (or at least as much as definable in Gospel currently), or would that duplicate what you're already working on?
Predicates and some easy Bytes specs
E.g. I think the initial comments in the Bytes module can be quite nicely translated into Gospel as they're already semi-formal:
And these predicates can be used quite nicely when defining properties:
Specifying unchanged sequence elements
However some of the other functions' specifications turn out to be quite long if I also want to specify what doesn't change:
For
fill
this is doable, but I'm just worried that in a more complex data structure having to manually specify everything that stays the same would be quite error-prone and easy to forget some crucial part. Would be nice if there was a way to say:s
is identical toold s
, except for anything that is explicitly defined to be different (although I realize it'd then be quite hard for a prover likecameleer
to come up with a way to formally express that).I think lenses might give an idea for a good way out of this: if I could get a mutable view on an
'a seq
and define properties just on that, and have a default 'everything not part of the view is the same' it might simplify specifications:And then
fill
could be specificied as:(although I'm not sure how convenient it'd be to work with that form in proofs)
The problem is you wouldn't be able to use more than one of these because then the first view would add an incorrect
= old s
constraint, it'd probably have to a predicate that handles a list of ranges, uses fold_left (or fold_right) on them to build up a growing list of ranges, and then at the end add the old constraints for anything not part of that range (being able to easily turn intervals into sets would probably be useful here to translate all this into set membership in the end).I'm probably missing something obvious here, is there an easier way to specify
old
?I was thinking to use Seq.set here, but IIUC the forall would make all those sets apply in parallel which would end up with equations like this for pos=1, len=2:
(which would be a contradiction)
Perhaps it is writable using Seq.fold_left and passing in the old value just once? (But cameleer doesn't implement fold_left yet, so I wouldn't be able to try that out).
Seq.iter?
There are also functions that are difficult to specify in the Gospel language in the first place, like
iter
(I'm thinking this can be done as Seq.fold_left on a unit, but it looks a bit unnatural), and iteration would come up in almost any data structure, so having a Seq.iter would be useful (even if they desugar to fold_left, etc.)Beta Was this translation helpful? Give feedback.
All reactions