lang_2023/tests/match.lang

18 lines
448 B
Text
Raw Normal View History

decl fruit_cost : Fruit -> Int
2023-03-31 12:10:12 +03:00
def fruit_cost : fruit = {
2023-05-11 23:14:36 +03:00
return (match fruit with
| $Banana -> 11
| $Apple | $Orange -> 7)
2023-03-31 12:10:12 +03:00
}
decl amount_to_string : Int -> Bool -> String
2023-03-31 12:10:12 +03:00
def amount_to_string : x is_zero_separated = {
2023-04-26 01:02:53 +03:00
const ans = match x with
| 0 ? is_zero_separated -> "Zero"
| 0 | 1 | 2 | 3 | 4 -> "Few"
2023-05-11 23:14:36 +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
}