Skip to main content
Version: 1.5.0

Declaring

Until now, we dealt with implicit namespace types, also know as interfaces. Having explicitly declared interfaces enables abstraction and reusability by inclusion of interfaces. Interfaces are introduced by the keyword interface:

interface Euro_INTF {
type t;
const add: (a: t, b: t) => t;
const one: t;
const two: t;
};

An interface can then be used to constrain a namespace definition, ensuring that said namespace contains at least the types and values listed in the given interface. An interface constraint is introduced by the keyword implements:

namespace Euro implements Euro_INTF {
export type t = nat; // No more abstract
export const add = (a: t, b: t) : t => a + b;
export const one: t = 1n;
export const two: t = 2n;
};

Note how namespace definitions must instantiate any abstract type in their interface: here Euro.t.