Function Declarations

Functions

To declare a function, provide its return value type:

let
  function not (i : int) : int =
    if i = 0 then
      1
    else
      0
in
  ...
end

A procedure has no value return type:

let
  function print_conditional(s : string, i : int) =
    if i then
      print(s)
    else
      print("error")
in
  print_conditional("foo", 1)
end

Functions can be recursive, but mutually recursive functions must be in the same sequence of function declarations (no other declaration should be placed between them).

See the semantics of function calls for the argument passing policy (see Expressions).

Primitives

A primitive is a built-in function, i.e. a function which body is provided by the runtime system.

See Predefined Functions for the list of standard primitives.

Aside from the lack of body, and henceforth the absence of translation, primitive declarations behave as function declarations. They share the same name space, and obey the same duplicate-name rule. For instance:

let
  primitive one() : int
  function  one() : int = 1
in
  ...
end

is invalid and must be rejected with the exit status set to 4.