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.

Chapter 11<br />

Static Parameters<br />

Trait, object, and functional declarations may be parameterized with static parameters. Static parameters are static<br />

variables listed in white square brackets and immediately after the name of a trait, object, or functional and<br />

they are in scope of the entire body of the declaration. Static parameters may be instantiated with static expressions<br />

discussed in Section 13.27. In this chapter, we describe the forms that these static parameters can take.<br />

Syntax:<br />

StaticParams ::= StaticParamList<br />

StaticParamList ::= StaticParam ( , StaticParam) ∗<br />

11.1 Type Parameters<br />

Syntax:<br />

StaticParam ::= Id [Extends] [absorbs unit ]<br />

Static parameters may include one or more type parameters. Syntactically, a type parameter consists of an identifier followed<br />

by an optional extends clause, followed by an optional “absorbs unit ” clause (described in Section 35.4).<br />

If a type parameter does not have an extends clause, it has an implicit “extends Object ” clause.<br />

Type parameters are instantiated with types such as traits, tuple types, and arrow types (See Chapter 8 for a discussion<br />

of <strong>Fortress</strong> types). We use the term naked type variable to refer to an occurrence of a type variable as a stand-alone<br />

type (rather than as a parameter to another type). Type parameters can appear in any context that an ordinary type can<br />

appear, except that a naked type variable must not appear in the extends clause of a trait or object declaration nor as<br />

the type of a wrapped field (discussed in Section 10.2).<br />

Here is a parameterized trait List:<br />

trait ListT<br />

first():T<br />

rest():ListT<br />

cons(T):ListT<br />

append(ListT):ListT<br />

end<br />

81

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

Saved successfully!

Ooh no, something went wrong!