effekt-lang / effekt-lang/effekt
[To be discussed] Allow match guards as boolean expressions
- Dominant language
- Scala
- Stars
- 469
- Forks
- 41
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 23
Description
When coming from other languages, it is surprising that you can't, e.g. use `not(x is Cons(_,Red()))` in an `if`/`while`.
Also, splitting up longer conditionals using bindings is not possible when using match guards.
Using match guards instead of equality predicates is especially useful on llvm, since there is no `infixEq` on data types, and no generic `equals` implemented.
## Examples
```effekt
while(not(asBool(cmd is Some("quit")))) {
cmd = readCmd()
//...
}
```
## Proposal
Allow `x is p` in expression position and desugar it to `if(x is p) { true } else { false }`.
## Considerations and Alternatives
- It might be clearer to add some syntax for this, e.g. `asBool(x is p)` (better name required)
- Regarding binding, the behaviour is slightly unexpected when changing to booleans. This could be ameliorated by adding a check that the converted pattern does not bind anything. Note that this disallows certain patterns, though (e.g. `(x is Some(y) and valid(y)`).
- For the usecase of `while(not...)`, it would be possible to add `until`, e.g.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.