Flix (programming language): Difference between revisions

Content deleted Content added
Citation bot (talk | contribs)
Altered title. Added chapter. Removed parameters. Some additions/deletions were parameter name changes. | Use this bot. Report bugs. | #UCB_CommandLine
correct examples
Line 48:
 
<syntaxhighlight lang="flx">
def main(): Unit &\ ImpureIO =
Console.printLine("Hello World!")
</syntaxhighlight>
 
The type and effect signature of the <code>main</code> function specifies that it has no parameters, returns a value of type <code>Unit</code>, and that the function has the IO effect, i.e. is impure. The <code>main</code> function is impure because it invokes <code>printLine</code> which is impure.
 
=== Algebraic data types and pattern matching ===
Line 60:
<syntaxhighlight lang="flx">
enum Shape {
case Circle(IntInt32), // has circle radius
case Square(IntInt32), // has side length
case Rectangle(IntInt32, IntInt32) // has height and width
}
</syntaxhighlight>
Line 71:
 
<syntaxhighlight lang="flx">
def area(s: Shape): IntInt32 = match s {
case Circle(r) => 3 * (r * r)
case Square(w) => w * w
Line 83:
 
<syntaxhighlight lang="flx">
def twice(f: IntInt32 -> IntInt32): IntInt32 -> IntInt32 = x -> f(f(x))
</syntaxhighlight>
 
Line 114:
 
<syntaxhighlight lang="flx">
def point2d(): {x: IntInt32, y: IntInt32} = {x = 1, y = 2}
</syntaxhighlight>
 
Line 120:
 
<syntaxhighlight lang="flx">
def sum(r: {x: IntInt32, y: IntInt32 | rest}): Int = r.x + r.y
</syntaxhighlight>