-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design Proposal: Support for enumeration #1753
Comments
Note for myself: it's also possible this would help users achieve successful verification when working with iteration. That's because a If an enumeration has something like a |
Another related issue: #424 - it's likely what we want is a built-in way to get an "enumerator" value for a given |
What prevents you from enumerating over a collection using a higher order |
Great question - that's certainly possible now, but a lot more limited than a hypothetical The standard library already has higher-order functions like var oneThroughFive := [1, 2, 3, 4, 5];
var sixThroughTen := Map(oneThroughFive, x => x + 5); But the second argument to var oneThroughFive := [1, 2, 3, 4, 5];
Map(oneThroughFive, x => { // Invalid syntax - has to be an expression
print x;
}); However, this is exactly one possible solution I'm strongly considering: supporting "anonymous methods" and "method references" as first class values, so you COULD write |
(Apologies for the fuzzy description, hopefully this can be refined as we think through the implications)
The recently-added
for
loop construct only supports iterating over integer values. There is frequently a strong need in Dafny code to define enumerations of values in more flexible or runtime-efficient ways thanseq<T>
values, such as streams of values, and to perform actions or transformations on each value in sequence (or perhaps even in parallel whenever Dafny supports concurrency :).There are two parts to this: how to define an enumeration (and I'm using that term to avoid conflict with the existing
iterator
construct, which is one possible way to define an enumeration but not the only one) and what features we offer to operate on enumerations, such asforeach
loops.Strongly coupled to #413, which talks about having
string
correctly and efficiently model Unicode encodings: if your abstract string value is a sequence of Unicode scalar values but your runtime representation is, say, UTF-8 bytes, then you really want your code to iterate over “characters” instead of doing random access indexing.@seebees' standard library PR (dafny-lang/libraries#29) is partially inspired by this need, and could also benefit from more built in support for enumerations.
The text was updated successfully, but these errors were encountered: