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
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(
case Square(
case Rectangle(
}
</syntaxhighlight>
Line 71:
<syntaxhighlight lang="flx">
def area(s: Shape):
case Circle(r) => 3 * (r * r)
case Square(w) => w * w
Line 83:
<syntaxhighlight lang="flx">
def twice(f:
</syntaxhighlight>
Line 114:
<syntaxhighlight lang="flx">
def point2d(): {x:
</syntaxhighlight>
Line 120:
<syntaxhighlight lang="flx">
def sum(r: {x:
</syntaxhighlight>
|