2.1 KiB
Namespaces
Namespaces are the primary organizational unit of Ava. Every Ava file must define a namespace. The namespace is ALWAYS the first line of the file.
Syntax
Each namespace is an ordered, delimited, list of names. Each name is
separated by the .
character.
<name>[.<name>]*
- At least one name MUST be specified.
- CANNOT contain more than one
.
character in a row. - CANNOT begin with
.
character. - CANNOT end with
.
character. - CANNOT use a Reserved Name.
Examples
foo
foo.bar.baz
language.v0
collections.v0
Reserved Names
Any namespaces provided with a particular Ava distribution are considered reserved. This means that, for example, the following namespaces cannot be used:
language
collections
Language Namespace
The language
namespace is automatically imported into every Ava file.
Exports
Each namespace MAY export defintions using the export
keyword. If some
definition is exported, it may be imported into another namespace.
Definitions are NOT exported by default -- it is an opt-in process. As noted in
the Definitions documentation, the export
keyword may be
used at the beginning of any definition.
Imports
Imports immediately follow the namespace definition in each file. Each file may have zero or more imports. Imports bring definitions from another namespace into scope.
Syntax
Each import is a single, fully-qualified name. Imported names MAY be mapped to some alternative name. An import may refer to a specific namespace or it may refer to some specific definition within a namespace.
TODO: Account for type classes. How can we easily import instances? One option
is to NOT do this. Ever. Just resolve EVERY possible instance
during
compilation and make them available within the scope of the program. Global.
Very strict one-instance-per-thing side-effect, but could be useful.
import <namespace>[.<definition name>] [as <name>]
Examples
import collections.NonEmptyList as NEL
import collections.Queue
import collections