> For the complete documentation index, see [llms.txt](https://clarity-7.gitbook.io/clarity-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://clarity-7.gitbook.io/clarity-docs/clarity-moniversive-invariant-static-mis/education-learn-the-language-.mis/05-state-signals-fail.md).

# 5 — State, signals, fail

> Generated 2026-07-29T03:15:30Z

MIS modules can declare **persistent fields** and **observable events** alongside invariants and outcomes. Together they replace mutable object fields + event emits in other languages.

## `state`

```mis
state counter;
state max_step;
```

State names are module-scoped. Outcomes refer to them in constraints (`counter == counter + n`). Invariants constrain state globally (`counter >= 0`). Declare all state up front so reviewers see the memory footprint immediately.

## `signal`

```mis
signal Tick(n: u64);
```

Signals describe observable emissions with typed payloads. They correspond to “something the outside world can listen for” without embedding logging calls in outcome bodies in this authoring style.

## `fail`

```mis
fail Overflow;
fail ZeroStep;
```

Named failure modes document how an outcome may refuse progress. Pair fails with `require` gates (`require n > 0` aligns with `ZeroStep`). Not every module declares `fail`, but counter examples use them to teach explicit failure vocabulary.

## Counter module (full)

```mis
module CounterLesson {

  invariant counter_non_negative: counter >= 0;
  invariant step_positive_bounded: max_step <= 1000;

  state counter;
  state max_step;

  signal Tick(n: u64);
  fail Overflow;
  fail ZeroStep;

  outcome bump(n: u64) {
    require n > 0;
    require n <= max_step;
    constraint counter == counter + n;
  }

  outcome reset() {
    constraint counter == 0;
  }
}
```

Walkthrough in prose:

When **`bump`** runs, the module requires a positive step no larger than **`max_step`**. The constraint updates **`counter`**. Invariants guarantee **`counter`** never goes negative and steps stay bounded — even if a caller invokes **`bump`** repeatedly, the module laws were stated before any outcome.

**`reset`** is intentionally minimal: one constraint forcing **`counter`** to zero. There is no `require` because reset is unconditional in this lesson (a real module might add authorization outcomes).

See also [Syntax rules](/clarity-docs/clarity-moniversive-invariant-static-mis/language-and-coding-breakdown/syntax.md) for the same keywords in table form.

Next: [Types & data](/clarity-docs/clarity-moniversive-invariant-static-mis/education-learn-the-language-.mis/06-types-and-data.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://clarity-7.gitbook.io/clarity-docs/clarity-moniversive-invariant-static-mis/education-learn-the-language-.mis/05-state-signals-fail.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
