Skip to content

How do I use adt in ensures/requres? #4372

Answered by atomb
vkensou asked this question in Q&A
Discussion options

You must be logged in to vote

You can write that example something like this:

datatype NullableInt = Some(value: int) | None

method Foo() returns (result: NullableInt)
    ensures result.Some? && result.value > 0
{
  return Some(1);
}

The expression result.Some? evaluates to true if the value of result was constructed with the Some constructor, and the right-hand side of && can assume that the left-hand side is true, so you can directly extract the value field. You could also use a match expression in the ensures clause, but that would be more verbose in this case.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@vkensou
Comment options

Answer selected by vkensou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants