Visibility

Private visibility

A private declaration is visible within the same module and nowhere else.
To mark any declaration as private, put a - in front of the name. (It is not a part of the name.)

import ./foo-bar main void() log foo-bar log foo # Won't workfoo-bar string() "{foo}{bar}" -foo string() "foo" -bar string() "bar"

Functions, types, and specs can all be made private.
Even the individual fields of a record can be made private.

import ./my-record main void() a r = () log a.x log a.y # Won't workr record x nat -y nat new r() 0, 0

By default, the implicit new function for a record is as visible as the least-visible field.
That means that if there is a private field, new defaults to private. If all fields are at the default visibility, so is new.

It's possible to make new private even when the fields are not:

import ./private-new-record main void() a r = () log a.x, a.y # fields are not private _ r = 1, 2 # Won't workr record -new x nat y nat new r() 0, 0

Internal visibility

The default visibility is called internal.
An internal declaration is visible if imported using a relative import path like ./foo, but not if imported using a non-relative import path like foo/bar.
(See "config.kid" for how to set up non-relative imports.)

The assumption is that relative imports indicate a closer relationship between modules.
Non-relative imports are intended for libraries, which may want to hide implementation details.

Public visibility

To make a declaration visible to all importers, make it public with +.

+my-public-function void() ()

Explicit internal visibility

A declaration may be marked explicitly internal using ~.
This is rarely needed, except in these cases:

  • When defining a function named -, ~, or +, a visibility mark is mandatory, since otherwise the function name looks like the visibility mark.
    So you might declare: ~ - my-type(a my-type) .
    This declares a function - with internal (~) visibility.
  • You may want an internal field on a public record:
+public-record record ~internal-field bool

Ignoring visibility

If you don't want to deal with visibility, you can just leave everything at the default internal visibility.
This won't be a problem so long as you import your own code using relative imports.

However, if you are writing a library for use by others, you should mark the public API with +.