Flix (programming language): Difference between revisions

Content deleted Content added
Line 32:
 
<syntaxhighlight lang="Scala">
/// An algebraic data type for shapes.
...
enum Shape {
case Circle(Int), // circle radius
case Square(Int), // side length
case Rectangle(Int, Int) // height and width
}
</syntaxhighlight>
 
 
<syntaxhighlight lang="Scala">
/// Computes the area of the given shape using pattern matching and basic arithmetic.
def area(s: Shape): Int = match s with {
case Circle(r) => 3 * (r * r)
case Square(w) => w * w
case Rectangle(h, w) => h * w
}
</syntaxhighlight>