Skip to content

Namespaces

Bill Hails edited this page May 10, 2026 · 17 revisions

Namespaces are separate files that can be accessed by using the link statement in the let part of a file. For example

let
    link "listutils.fn" as list;
in
    print(list.sort("cba"))

prints "abc"

The as part is not optional, in this example it defines the symbol list to be the namespace populated with the contents of the nominated file. The functions, types and type constructors defined in that file become available by prepending them with the namespace and a dot.

Files to be linked as namespaces must begin with the keyword namespace and consist only of typedefs, functions operators and macros at the top-level. No nests or let/in constructs are valid at the top-level of a namespace file. User-defined print functions (see Print) are valid in namespaces.

The path to the file to be linked is initially taken as relative to the parent file, but additional directories to be searched can be supplied on the command line with the --include=dir option.

Import and Export

plain (non-lazy) functions can be imported from a namespace using the following directive:

import <namespace>.<function> [as <alias>];

after which <function> or <alias> is an alias for <namespace>.<function>.

Operators can be imported similarly:

import <namespace> operator <template-string>;

where <template-string> is the same string used to define the operator, i.e. "_|>_".

Macros can also be imported as:

import <namespace> macro <name>;

Operators and macros to be imported must be prefixed with the export keyword at the point of their definition in the namespace. Functions do not need to be exported.

Utility Libraries

I've started to build out some basic library support using namespaces. Currently there is only listutils.fn and ambutils.fn and you can read about those in the next sections.

Next: List Utils

Clone this wiki locally