File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ /// Returns the area of the rectangle `r`.
2+ /// The record `r` must have `x` and `y` labels, and no other labels.
3+ def area2(r: {x = Int32 , y = Int32 }): Int32 = r.x * r.y
4+
5+ /// Computes the area of various rectangle records.
6+ /// Note that the order of labels is immaterial.
7+ def areas(): List[Int32 ] =
8+ area2({x = 1 , y = 2 }) ::
9+ area2({y = 2 , x = 3 }) :: Nil
10+
11+ /// Returns the area of the polymorphic record `r`.
12+ /// Note that the use of the type variable `a` permits the record `r`
13+ /// to have labels other than `x` and `y`.
14+ def polyArea(r : {x = Int32 , y = Int32 | a}): Int32 = r.x * r.y
15+
16+ /// Computes the area of various rectangle records.
17+ /// Note that some records have additional fields.
18+ def polyAreas(): List[Int32 ] =
19+ polyArea({x = 1 , y = 2 }) ::
20+ polyArea({x = 2 , y = 3 , z = 4 }) :: Nil
21+
22+ // def main(): Unit \ IO =
23+ // areas() |> println;
24+ // polyAreas() |> println
You can’t perform that action at this time.
0 commit comments