lang_2023/tests/match.lang

19 lines
508 B
Text
Raw Permalink Normal View History

2023-06-03 19:01:03 +03:00
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)
2023-03-31 12:10:12 +03:00
}
2023-06-03 19:01:03 +03:00
decl amount-to-string : \int -> \bool -> \string
def amount-to-string : x is-zero-separated = {
2023-07-03 19:05:50 +03:00
let ans = match x with
2023-06-03 19:01:03 +03:00
| 0 ?? is-zero-separated -> "Zero"
| 0 | 1 | 2 | 3 | 4 -> "Few"
2023-06-03 19:01:03 +03:00
| x ?? (5--9)..contains: x -> "Several"
| x ?? (10--19)..contains: x -> "Pack"
| _ -> "Lots"
2023-03-31 12:10:12 +03:00
return ans
}