You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let example_3 (s:sign) : string =
match s with
| v when v = (-1) -> "negative"
| 1 -> "positive"
| 0 -> "zero"
I'm not sure in what contexts the "match ... when" syntax is supported. I've gotten the error "When clauses are not yet supported in --verify mode; they will be some day" when I attempted to use it previously, so it's not clear what is OK and what isn't.
For example, we can't match on a option sign in this way, that triggers the "not yet supported" error.
It is a parser issue, negative int literals are not supported as patterns in the parser.
As a workaround, you could also use if then else:
let example_1 (s:sign) : string =
if s = -1 then "n"
else if s = 1 then "p"
else begin
assert (s == 0); //not necessary, just for illustration
"z"
end
let example_2 (s:option sign) : string =
match s with
| None -> "none"
| Some s -> example_1 s
when clauses are not yet supported for all practical purposes. (The typechecker has an internal "lax" mode of operation that does not verify code, that's where when may be used.)
There doesn't seem to be a way to match on a negative integer. Here's a small reproduction:
There is a syntax error in the -1 case, with or without parentheses.
I initially ran into this case while trying to use an
optional sign
soSome (-1)
has the same problem.The text was updated successfully, but these errors were encountered: