Chapter 5. Static Load

In ATS, static load (or staload for short) refers to the creation of a namespace populated with the declared names in a loaded package.

Suppose that a file named foo.sats contains the following code:

// datatype aDatatype = | A | B of (int, int) // val aValue: int fun aFunction: int -> int //

The following staload-declaration introduces a namespace FOO for the names declared in foo.sats:

staload FOO = "foo.sats"

The prefix $FOO. needs to be attached to a name in the namespace FOO in order for it to be referenced. For instance, the names available in the namespace FOO are all referenced in the following code:

val a: $FOO.aDatatype = $FOO.A() val b: $FOO.aDatatype = $FOO.B(0, $FOO.aFunction($FOO.aValue))

If the file foo.sats is staloaded as follows for the second time:

staload FOO2 = "foo.sats"

then foo.sats is not actually loaded by the compiler. Instead, FOO2 is simply made to be an alias of FOO.

It is also allowed for foo.sats to be staloaded as follows:

staload "foo.sats"

In this case, the namespace for the names declared in foo.sats is opened. For instance, the following code shows that these names can now be referenced directly:

val a: aDatatype = A() val b: aDatatype = B(0, aFunction(aValue))

Let us suppose that we have the following sequence of declarations:

val aValue = 0 staload "foo.sats" val anotheValue = aValue + 1

Does the second occurrence of aValue refer to the one introduced in the first declaration, or it refers to the one declared inside foo.sats? The answer may be a bit surprising: It refers to the one introduced in the first declaration as a binding for the occurrence of a name is resolved in ATS by searching first through the available names delcared in the same file.