YukonModule.PolyFun.PFunctor.Handler.part0
DefinitionYukon_c7f6fc75577fee178fc2046ebetter-codes
Source module PolyFun.PFunctor.Handler.
Definition code
/-
Copyright (c) 2026 PolyFun Contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Devon Tuma
-/
module
public import Definitions.Def_Yukon_e56a429acec69be6a69f4fcc
public import Mathlib.Data.PFunctor.Multivariate.Basic
public import Init
meta import Definitions.Def_Yukon_e56a429acec69be6a69f4fcc
set_option backward.isDefEq.respectTransparency.types false
/-!
# Monadic Handlers for Polynomial Functors
A `PFunctor.Handler m q` chooses a direction of `q` at each position, with the
choice interpreted in the type constructor `m`. This is the generic interface
consumed by `FreeM.liftM`; it does not depend on machines or dynamical systems.
In particular, taking `m := StateT σ n` threads one shared runtime state through
every handled position. That ambient state is distinct from a dynamical
system's private operational state.
-/
@[expose] public section
universe u v uA uI
namespace PFunctor
/-- A **handler** for the interface `q`: a monadic choice of direction at each
position (a Kleisli section of `q`). With `m := Id` this is an ordinary
dependent choice of one direction at every position, while a probabilistic
monad gives a randomized choice. -/
abbrev Handler (m : Type u → Type v) (q : PFunctor.{uA, u}) :=
(a : q.A) → m (q.B a)
namespace Handler
/-- An effectful stateful handler for `q`: on each position it reads a state,
performs effects in `m`, and returns a direction together with the next state.
This is a transparent name for `Handler (StateT S m) q`, so it introduces no
new data or laws. At `m := Id` it is the pure Kleisli--Mealy presentation used
by `Responder.equivStateHandler`. -/
abbrev Stateful (m : Type u → Type v) (S : Type u)
(q : PFunctor.{uA, u}) :=
Handler (StateT S m) q
/-- Combine monadic handlers for an indexed family into a handler for its
indexed coproduct. -/
def sigma {I : Type uI} {P : I → PFunctor.{uA, u}} {m : Type u → Type v}
(f : (i : I) → PFunctor.Handler m (P i)) : PFunctor.Handler m (PFunctor.sigma P) :=
fun a => f a.1 a.2
@[simp]
theorem sigma_apply {I : Type uI} {P : I → PFunctor.{uA, u}} {m : Type u → Type v}
(f : (i : I) → PFunctor.Handler m (P i)) (i : I) (a : (P i).A) : sigma f ⟨i, a⟩ = f i a :=
rfl
end Handler
end PFunctor
Source