原文
class Rect(left, top, right, bottom) fun area(r): let w = r.right - r.left let h = r.bottom - r.top w*h area(Rect(0, 0, 10, 5))
class Rect(left, top, right, bottom) fun rect_like_to_rect(v): match v | Rect(_, _, _, _): v | {"LT": [l, t], "RB": [r, b]}: Rect(l, t, r, b) | {"TL": [t, l], "RB": [b, r]}: Rect(l, t, r, b) rect_like_to_rect({"TL": [0, 2], "RB": [10, 5]}) rect_like_to_rect({"LT": [0, 2], "RB": [10, 5]})
fun all_same([str0, str, ...]): all(str0 == str, ...) all_same(["hello", "hello", "hello"]) all_same(["hello", "goodbye", "hello"])
class Posn(x, y) fun flip_all([Posn(x, y), ...]): [Posn(y, x), ...] flip_all([Posn(1, 2), Posn(3, 4)]) flip_all([Posn(5, 6)])