Skip to main content

Program declarations

Program declarations are declarations that are defined at the program level. These declarations can be accessed by other programs (refer to the sections on Libraries). Program declarations are also the entrypoint for data APIs: a data API exposes a program declaration, typically called main.

For instance:

main(name: string) =
"Hello " + name

This example includes a program declaration called main. The program declaration main receives a parameter called name. The body of the declaration is an expression that prepends the string "Hello " to the name passed as an argument.

Since main is a program declaration, it can be loaded by other programs or used as a data API.

Program declarations have some restrictions:

  • program declarations can only be declared at the top-level of a program, i.e. cannot be nested inside other declarations;
  • program declarations cannot do recursive calls.

Refer also to the section on Let declarations and functions for the difference between different types of declarations and when to use program declarations.

Optional parameters‚Äč

Program declarations can have optional parameters, e.g.:

main(name: string = "John") =
"Hello " + name

This program can be used without any argument, in which case the result is "Hello John", or with an argument.