lang_2023/tests/match.lang
2023-07-03 19:05:50 +03:00

18 lines
508 B
Text

decl fruit-cost : \fruit -> \int
def fruit-cost : fruit = {
var fruit-copy = fruit
return (match <- fruit-copy with // consuming match
| $banana -> 11
| $apple | $orange -> 7)
}
decl amount-to-string : \int -> \bool -> \string
def amount-to-string : x is-zero-separated = {
let ans = match x with
| 0 ?? is-zero-separated -> "Zero"
| 0 | 1 | 2 | 3 | 4 -> "Few"
| x ?? (5--9)..contains: x -> "Several"
| x ?? (10--19)..contains: x -> "Pack"
| _ -> "Lots"
return ans
}