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.

e called with. In other words, we expand these declarations so that there exists a declaration for each number of<br />

arguments that can be passed to it.<br />

A declaration with k keyword parameters corresponds to 2 k declarations which cannot be called with elided arguments,<br />

one for each subset of the keyword parameters. For example, the following declaration:<br />

f(x = 5, y = 6, z = 7) : Z<br />

would be expanded into:<br />

f(x = 5, y = 6, z = 7) : Z<br />

f(x = 5, y = 6) : Z<br />

f(x = 5, z = 7) : Z<br />

f(y = 6, z = 7) : Z<br />

f(x = 5) : Z<br />

f(y = 6) : Z<br />

f(z = 7) : Z<br />

f() : Z<br />

Note that even though expanded declarations still have keyword parameters, they cannot be called with elided arguments<br />

any more. A declaration with keyword parameters is applicable to a call if any one of the expanded declarations<br />

is applicable.<br />

A declaration with a varargs parameter corresponds to an infinite number of declarations, one for every number of<br />

arguments that may be passed to the varargs parameter. In practice, we can bound that number by the maximum<br />

number of arguments that the functional is called with anywhere in the program (in other words, a given program<br />

will contain only a finite number of calls with different numbers of arguments). <strong>The</strong> expansion described here is a<br />

conceptual one to simplify the description of the semantics; we do not expect any real implementation to actually<br />

expand these declarations at compile time. For example, the following declaration:<br />

f(x : Z, y : Z, z : Z . . .) : Z<br />

would be expanded into:<br />

f(x : Z, y : Z, z : Z . . .) : Z<br />

f(x : Z, y : Z) : Z<br />

f(x : Z, y : Z, z 1 : Z) : Z<br />

f(x : Z, y : Z, z 1 : Z, z 2 : Z) : Z<br />

f(x : Z, y : Z, z 1 : Z, z 2 : Z, z 3 : Z) : Z<br />

. . .<br />

Notice that the expansion includes the original declaration. This declaration is retained to account for the case when a<br />

tuple expression with a varargs expression is passed as an argument to a call; even though this declaration still has a<br />

varargs parameter, it’s called with a fixed number of arguments. A declaration with a varargs parameter is applicable<br />

to a call if any one of the expanded declarations is applicable.<br />

15.5 Overloading Resolution<br />

Several declarations may be applicable to a given functional call. <strong>The</strong>refore, it is necessary to determine which<br />

declaration is dispatched to. <strong>The</strong> basic principle is that, for any functional call, we wish to identify a unique declaration<br />

that is the most specific among all declarations applicable to the call at run time. If there is no such declaration, then<br />

the call is undefined, which is a static error. If there are two or more such declarations, no one of which is more specific<br />

than all the others, the call is said to be ambiguous, which is also a static error. As discussed in Chapter 33, it is a<br />

static error for overloaded declarations to admit ambiguous calls at run time, whether such calls actually appear in the<br />

program or not.<br />

123

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

Saved successfully!

Ooh no, something went wrong!