Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Annotations

Flix supports a limited set of built-in annotations.

For example, the @Test annotation marks a function as a test. The test framework runs every such function and reports whether it passed:

@Test
def testSum01(): Unit \ Assert =
    Assert.assertEq(expected = 6, sum(1 :: 2 :: 3 :: Nil, 0))

As another example, the @Tailrec annotation asks the compiler to verify that every recursive call in a function is a tail call. The sum function below passes the check, because the recursive call is the last thing it does:

@Tailrec
def sum(l: List[Int32], acc: Int32): Int32 = match l {
    case Nil     => acc
    case x :: xs => sum(xs, acc + x)
}

Flix has the following built-in annotations:

AnnotationMeaning
@TestRuns the function as a test. See Test Framework.
@SkipSkips a @Test function. The test is reported as skipped, not run.
@DefaultHandlerMarks the default handler of an effect. See Default Handlers.
@TailrecVerifies that every self-recursive call is a tail call. See Tail Recursion.
@TerminatesVerifies that the function is structurally recursive. See Termination Checking.
@InlineMakes the compiler always inline the function.
@DontInlineMakes the compiler never inline the function.
@DeprecatedDocuments that the declaration is deprecated.
@ExperimentalDocuments that the declaration may change or be removed without warning.
@LazyDocuments that the function uses lazy evaluation.
@LazyWhenPureDocuments that the function uses lazy evaluation when given a pure function. See Purity Reflection.
@ParallelDocuments that the function uses parallel evaluation.
@ParallelWhenPureDocuments that the function uses parallel evaluation when given a pure function. See Purity Reflection.

The last six annotations are documentation. They are shown in the API docs and as hints in the editor, but they do not change how the compiler translates the function.

Note: Flix has no @Override annotation. An instance that overrides a default implementation from its trait marks the function with the redef keyword instead.