19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

swap(x :Object, y : Object) = (y, x)<br />

Similarly, function parameter type can often be inferred from the body of the function. When a type can be inferred<br />

for a parameter from the body of the function, that parameter type need not be declared explicitly. Thus, the following<br />

declaration of swap has the same parameter type and return type as the above declarations:<br />

swap(x, y) = (y, x)<br />

See Chapter 20 for a discussion of type inference in <strong>Fortress</strong>.<br />

<strong>The</strong> following function wrap :<br />

wrap(xs,ys = xs) = [xs ys]<br />

returns an array containing its parameters. If a value for only the parameter xs is given to wrap at a call site, the value<br />

of xs is bound to ys as well, and an array that contains xs as both of its indices is returned.<br />

12.2 Function Applications<br />

<strong>Fortress</strong> provides overloaded functions (as described in Chapter 15); there may be multiple function declarations with<br />

the same function name in a single lexical scope. Thus, we need to determine which function declaration are applicable<br />

to a function application.<br />

If a function’s argument type is () , then function declarations with the following forms of parameter lists are considered<br />

to be applicable:<br />

• () which means the same thing as ( : ())<br />

• (x :()) which is something programmers don’t ordinarily write<br />

• (x :T . . .)<br />

In the last case, x is bound to an empty HeapSequenceT .<br />

If a function’s argument type A is neither () nor a tuple type, then function declarations with the following forms of<br />

parameter lists are considered to be applicable:<br />

• (x :T) where A is a subtype of T<br />

• (x :T . . .) where A is a subtype of T<br />

In the last case, x is bound to a HeapSequenceT of length 1 , containing the actual argument value.<br />

If a function’s argument type A is a tuple type, then function declarations with the following forms of parameter lists<br />

are considered to be applicable:<br />

• (x :T) where A is a subtype of T<br />

• (x :T . . .) where A is a subtype of T<br />

• a parameter list with no varargs binding, provided that<br />

– type A has exactly as many plain types as the parameter list has plain bindings, and<br />

– for every keyword-type pair (described in Section 8.4) in A, the parameter list has a binding with the same<br />

keyword, and<br />

– for every element type in A, the type in the element type is a subtype of the type of the corresponding<br />

binding in the parameter list.<br />

87

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

Saved successfully!

Ooh no, something went wrong!