-
I define a NullableInt, and return a NullableInt in a method.
What did I do wrong? |
Beta Was this translation helpful? Give feedback.
Answered by
atomb
Aug 2, 2023
Replies: 1 comment 1 reply
-
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 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
vkensou
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can write that example something like this:
The expression
result.Some?
evaluates to true if the value ofresult
was constructed with theSome
constructor, and the right-hand side of&&
can assume that the left-hand side is true, so you can directly extract thevalue
field. You could also use amatch
expression in theensures
clause, but that would be more verbose in this case.