Supporting superior Seq subrange syntax #388
jaybosamiya
started this conversation in
Language design
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently we have the nice
[]operator for indexing into a range, but unfortunately we cannot use it to get subranges, instead requiring the annoyings.subrange(foo, bar)(or somewhat regularly, evens.subrange(foo as int, bar as int), but we can ignore that for now (related)).One approach to support
s[foo..bar]ands[foo..]ands[foo..=bar], ... is to modify the way we havespec_indexwork.Currently,
spec_indexis defined as an implemented method forSeq<A>as:The proposed alternative is to remove it from the implementation of
Seq<A>, instead introducing a newSpecIndextrait, with the following signature (inspired bystd::ops::Indexin Rust, just with changes, in order to try to keep the signature consistent with the above existingspec_index):The implementations for this
spec_indexwould look similar to:The blockers to this approach are:
std::ops::Rangeand such (this is probably an easy fix, since we could just have our own wrapper insidepervasivefor the same; alternatively, there is the much larger and broader question of supporting stuff directly from the Rust standard library, but that's probably out of scope for this discussion)The other alternative implementation I can think of to nicely support the superior subrange syntax is to not have any trait things at all, but instead just have the
verus!macro detect that there is a..showing up inside the[]and redirect tosubrangerather thanspec_index.Not entirely certain which of the two options we'd like to go with. The first feels more principled, but is blocked, while the latter seems like it would be easier to implement(?), but seems to lead to more "magic"? Maybe that's fine, given we already having things like
spec_addandspec_indexand such.Beta Was this translation helpful? Give feedback.
All reactions