Skip to content

Variables & Types

Give inputs and results explicit types.

Assignment creates a local variable and infers its type from the expression. Explicit public parameter and return types let both compiler and kernel validate data.

Complete example

Save the example as types.aal

types.aal
agent Tutorial is Agent
  public
    ability run(name: String?, count: Int) -> String effects()
      next = count + 1
      label = if name == None then "Guest" else name
      return "{label}: {next}"
Download .aal

Syntax explained

  1. Basic types include String, Int, Float and Bool. Int is arbitrary precision; Float is finite 64-bit floating point.

  2. String? permits a String or None. Check for None before using the value.

  3. You cannot freely reassign an integer variable to a string. An omitted annotation introduces Any, not a static type guarantee.

Build and run

Terminal
cargo run --locked --bin aalc -- check types.aal

cargo run --locked --bin aalc -- build types.aal -o types.aalc

cargo run --locked --bin aalc -- run types.aalc \
  --agent Tutorial --ability run \
  --args '{"name":null,"count":2}' \
  --state-dir .aal-tutorial/types --invocation types-1

Run with a fresh state directory. The returned value is shown below; the CLI also prints execution information.

Expected result
"Guest: 3"

Try it yourself

Set name to Ada and count to 9. Run with a new invocation ID; the result should be Ada: 10.

Language source and specification