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

Side conditions in pattern matching #2804

Open lukaszcz opened 3 weeks ago

lukaszcz commented 3 weeks ago

Allow side conditions in pattern matches:

| pat1 pat2 pat3 if condition := body

For example, allow to write

case lst of
| [x] if F x := B1
| [x] := B2
| _ := B3

instead of

case lst of
| [x] := 
  if
    | F x := B1
    | else := B2
| _ := B3

Syntax proposal:

case lst of
| [x] 
     | if F x := A
     | if G x := B
     | else := C (else branch is optional)
| _ := D;
paulcadman commented 3 weeks ago

This came up when we were writing the logic function for the simple counter application:

https://github.com/anoma/juvix-anoma-stdlib/blob/dcbc80536eadc5bc9a8b45cba259a987339dd768/examples/RawCounterTransaction.juvix#L26