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.

11.2 Nat and Int Parameters<br />

Syntax:<br />

StaticParam ::= nat Id<br />

| int Id<br />

Static parameters may include one or more nat and int parameters. Syntactically, a nat parameter consists of the<br />

special reserved word nat followed by an identifier. An int parameter consists of the special reserved word int<br />

followed by an identifier. <strong>The</strong>se parameters are instantiated at runtime with numeric values. A nat parameter may<br />

be used to instantiate other nat parameters, or to appear in any context that a variable of type N can appear, except<br />

that it cannot be assigned to. An int parameter may be used to instantiate other int parameters, or to appear in any<br />

context that a variable of type Z can appear, except that it cannot be assigned to.<br />

For example, the following function f :<br />

fnat n(x :Length 2n ) :Length n = sqrt(x)<br />

declares a nat parameter n , which appears in both the parameter type and return type of f .<br />

11.3 Bool Parameters<br />

Syntax:<br />

StaticParam ::= bool Id<br />

Static parameters may include one or more bool parameters. Syntactically, a bool parameter consists of the special<br />

reserved word bool followed by an identifier. <strong>The</strong>se parameters are instantiated at runtime with boolean values. <strong>The</strong>y<br />

may be used to instantiate other bool parameters, or to appear in any context that a variable of type Boolean can<br />

appear, except that they cannot be assigned to.<br />

For example, the following coercion declared in the trait Boolean:<br />

trait Boolean<br />

coercion bool b(x: BooleanLiteralb)<br />

end<br />

declares a bool parameter b , which appears in the parameter type. See Chapter 24 for a full declaration of Boolean.<br />

11.4 Dimension and Unit Parameters<br />

Syntax:<br />

StaticParam ::= dim Id<br />

| unit Id [ : DimRef ] [absorbs unit ]<br />

Static parameters may include one or more dim and unit parameters. Syntactically, a dim parameter begins with<br />

the special reserved word dim followed by an identifier. A unit parameter begins with the special reserved word<br />

unit followed by an identifier, optionally followed by the token : and a dimension, and the unit is thereby restricted<br />

to be a unit of the specified dimension. A unit parameter may include the clause “absorbs unit ”; the meaning of<br />

this is described in Section 35.4. A dim parameter is allowed to appear in any context that a dimension can appear. A<br />

unit parameter is allowed to appear in any context that a unit can appear.<br />

For example, here is a function that is parameterized with a unit:<br />

sqrtunit U(x: R64 U 2 ): R64 U = numericalsqrt(x/U 2 ) U<br />

82

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

Saved successfully!

Ooh no, something went wrong!