19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

the function is evaluated with the parameter of the function bound to the value of the argument expression. <strong>The</strong> value<br />

and the type of a function call are the value and the type of the function body.<br />

Here are some examples:<br />

sqrt(x)<br />

arctan(y, x)<br />

If the function’s argument is not a tuple, then the argument need not be parenthesized:<br />

sqrt 2<br />

sin x<br />

log log n<br />

13.7 Function Expressions<br />

Syntax:<br />

Value ::= fn ValParam [IsType] [Throws] ⇒ Expr<br />

Function expressions denote function values; they do not require evaluation. Syntactically, they start with the special<br />

reserved word fn followed by a parameter, optional return type, optional throws clause, ⇒, and finally an expression.<br />

<strong>The</strong> type of a function expression is an arrow type consisting of the function’s parameter type followed by the<br />

token → , followed by the function’s return type, and the function’s optional throws clause. Unlike declared functions<br />

(described in Chapter 12), function expressions are not allowed to include static parameters nor where clauses<br />

(described in Chapter 11).<br />

Here is a simple example:<br />

fn (x :Double) ⇒if x < 0 then −x else x end<br />

13.8 Operator Applications<br />

Syntax:<br />

Expr ::= Op Expr<br />

| Expr Op [Expr]<br />

Value ::= LeftEncloser ExprList RightEncloser<br />

To support a rich mathematical notation, <strong>Fortress</strong> allows most Unicode characters that are specified to be mathematical<br />

operators to be used as operators in <strong>Fortress</strong> expressions, as well as various tokens described in Chapter 16. Most of<br />

the operators can be used as prefix, infix, postfix, or nofix operators as described in Section 16.3; the fixity of an<br />

operator is determined syntactically, and the same operator may have definitions for multiple fixities.<br />

Syntactically, an operator application consists of an operator and its argument expressions. If the operator is a prefix<br />

operator, it is followed by its argument expression. If the operator is an infix operator, its two argument expressions<br />

come both sides of the operator. If the operator is a postfix operator, it comes right after its argument expression. Like<br />

function calls, argument expressions are evaluated in parallel. After evaluating argument expressions to values, the<br />

body of the operator definition is evaluated with the parameters of the operator bound to the values of the argument<br />

expressions. <strong>The</strong> value and the type of an operator application are the value and the type of the operator body.<br />

Here are some examples:<br />

95

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!