Next-gen subset type #1557
MikaelMayer
started this conversation in
Ideas
Replies: 2 comments 5 replies
-
|
Would something like work? |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
Dafny 4.0
Here is why and how it could be transformative. type MyInt = x : int | 0 <= x < 13 witness *Consider a 'desugared' version of predicate type MyInt(x: int) {
0 <= x < 13
} witness *Wow, it looks like we only need to add Interesting note: Predicates having more than one argument would be refinement types. For example: predicate type LessThan(j: int, i: int) {
j < i
} witness (0, 1)would enable us to modify: method returnLower(i: int) returns (j: int)
ensures LessThan(i, j) { .... }to the following, arguably "simpler": method returnLower(i: int) returns (j: LessThan(i)) { ... }Now, here is how we could use it method test() {
var i := ...
var j: LessThan(i) = returnLower(i);
// The type is the predicate. If the predicate is a predicate method,
// we can test it, else it's only in specification
} |
Beta Was this translation helpful? Give feedback.
2 replies
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.
-
We know we can do the following refactoring
to:
and we all like it. It is striking that putting the validation code inside the type name makes the methods more legible, and less specification error-prone.
I am thinking of a generalization of subset types, a kind of dependent types, which would enable the following refactoring:
==>
With such type declaration, it would enable to ensure we never return a C without it being built from some a and some b, and hold an invariant.
An idea to discuss.
Beta Was this translation helpful? Give feedback.
All reactions