Documentation

PolyFun.ITree.Events.State

State events #

A standard event signature for stateful computations. The polynomial functor StateE σ has two events:

interpState eliminates state events from a tree over StateE σ + E, threading an initial state through the computation and leaving every external E-event visible. runState is its conventional runner alias. Both use a direct productive corecursor, so their computation rules are exact equalities rather than merely weak bisimulations.

Rocq references:

inductive ITree.StateE.Shape (σ : Type uσ) :
Type uσ

The two state events. Shape.get returns the current state, Shape.put replaces it.

  • get {σ : Type uσ} : Shape σ

    Read the current state.

  • put {σ : Type uσ} (s : σ) : Shape σ

    Overwrite the current state with s : σ.

Instances For
    @[reducible]

    State events over a state space σ : Type u. The answer types are:

    • for get — σ (the value read);
    • for put _ — PUnit (the unit return of an assignment).
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      def ITree.StateE.get {σ : Type uσ} :
      ITree (StateE σ) σ

      Issue a get event, returning the current state.

      Equations
      Instances For
        def ITree.StateE.put {σ : Type uσ} (s : σ) :

        Issue a put event, returning PUnit.

        Equations
        Instances For

          State interpretation #

          def ITree.interpStateStep {σ : Type uσ} {E : PFunctor.{uEA, uσ}} {α : Type uα} (st : σ × ITree (StateE σ + E) α) :
          ↑(ViewPoly E (σ × α)) (σ × ITree (StateE σ + E) α)

          One productive layer of state interpretation. The corecursor state stores the current state together with the source tree. State operations become silent steps, while external events remain visible.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            def ITree.interpState {σ : Type uσ} {E : PFunctor.{uEA, uσ}} {α : Type uα} (t : ITree (StateE σ + E) α) (s : σ) :
            ITree E (σ × α)

            Interpret state operations in t, starting from s, and return the final state together with the computation result. External events remain visible.

            The direction universe of E agrees with that of σ only because the summands of the source signature StateE σ + E (PFunctor.add) share a direction universe. The final result universe is independent.

            Equations
            Instances For
              def ITree.runState {σ : Type uσ} {E : PFunctor.{uEA, uσ}} {α : Type uα} (t : ITree (StateE σ + E) α) (s : σ) :
              ITree E (σ × α)

              Conventional runner name for interpState.

              Equations
              Instances For