anoma / juvix

A language for intent-centric and declarative decentralised applications
https://docs.juvix.org
GNU General Public License v3.0
442 stars 54 forks source link

Add front-end support for case expressions boolean side conditions #2852

Open janmasrovira opened 1 week ago

janmasrovira commented 1 week ago

This pr introduces:

  1. front-end support (parsing, printing, typechecking) for boolean side conditions for branches of case expressions.
  2. Now if is a reserved keyword.

Example:

 multiCaseBr : Nat :=
    case 1 of
      | zero
        | if 0 < 0 := 3
        | else := 4
      | suc (suc n)
        | if 0 < 0 := 3
        | else := n
      | suc n if 0 < 0 := 3;

The side if branches must satisfy the following.

  1. There must be at least one if branch.
  2. The else branch is optional. If present, it must be the last.

Future work:

  1. Translate side if conditions to Core and extend the exhaustiveness algorithm.
  2. Add side if conditions to function clauses.