Effect Schema Lifting¶
These functions lift a base rule schema to values that carry an effect, such as a set of
alternatives or a continuation
(schema lifting). Which lifted rules exist
depends on the type classes the effect inhabits
(functor, applicative, monad, alternative) (McBride and Paterson, 2008; Wadler, 1992).
class_directed_lifts(base_schema, effect) and lift_rule_set(base_schemas, effects) emit the
lifted SchemaDecls, and each generated rule depends on the laws and scope conventions of its
effect instance.
effect_lifts
¶
Fixed schema shapes for semantic effect prefixes in chart parsers.
class_directed_lifts emits pure and forward apply for an
Applicative, bind for a Monad, and alt for an Alternative.
The base schema contributes its name to each generated name; these shapes
are fixed rather than derived from the base schema's domain and codomain.
A bare Functor and the arrow interfaces add no schemata.
Generated schemata use the chart's ordinary pattern matching. Distributive
laws can additionally generate swap schemata through make_swap_schema.
These semantic type prefixes are distinct from QIEC effect instances and
lexical handlers. Chart execution does not eliminate a prefix by invoking
a QIEC handler.
class_directed_lifts
¶
class_directed_lifts(base_schema: SchemaDecl, effect: object) -> tuple[SchemaDecl, ...]
Generate the class-driven lifts for base_schema under effect.
Membership in Applicative emits pure_T and forward apply_T;
Monad adds bind_T; Alternative adds alt_T. MonadPlus
receives both sets through its parent classes. A bare Functor and
arrow-only instances emit nothing.
These are fixed schema shapes. The base schema provides the suffix of their names, not a general transformation of its premises.
| PARAMETER | DESCRIPTION |
|---|---|
base_schema
|
The base schema being lifted.
TYPE:
|
effect
|
An effect instance (any class registered against the relevant
typeclass ABCs in
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of SchemaDecl
|
Zero or more schemata in the order |
Source code in src/quivers/stochastic/effect_lifts.py
make_swap_schema
¶
make_swap_schema(distributive_law: object, base_schema: SchemaDecl | None = None) -> SchemaDecl
Generate a swap_TU schema from a registered distributive law.
Given a DistributiveLaw λ : S ∘ T ⇒ T ∘ S, the chart
parser uses swap_TU to exchange sibling effect orderings at a
cell whose effect stack ends in T·U:
swap_TU[X : Cat] : T(U(X)) -> U(T(X))
The schema is consumed by the chart's commutation firing rule of Effects §4.4.
| PARAMETER | DESCRIPTION |
|---|---|
distributive_law
|
The law whose outer and inner monads the schema exchanges.
TYPE:
|
base_schema
|
The schema whose name the swap schema's name extends; the
name
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaDecl
|
The |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/stochastic/effect_lifts.py
swap_rule_set
¶
swap_rule_set(distributive_laws: tuple[object, ...]) -> tuple[SchemaDecl, ...]
Generate one swap_TU schema per registered distributive law.
The resulting tuple is appended to the chart parser's rule set alongside the class-driven lifts; the chart's commutation-firing dispatch picks each swap schema up by name.
| PARAMETER | DESCRIPTION |
|---|---|
distributive_laws
|
The registered distributive laws.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of SchemaDecl
|
One swap schema per law, in the order given. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If an entry is not a |
Source code in src/quivers/stochastic/effect_lifts.py
lift_rule_set
¶
lift_rule_set(base_schemas: tuple[SchemaDecl, ...], effects: tuple[object, ...]) -> tuple[SchemaDecl, ...]
Apply class_directed_lifts over a rule-set and effect-stack.
Returns the union of base schemas and all lifts produced for each (base_schema, effect) pair. The chart parser consumes the resulting tuple directly.
| PARAMETER | DESCRIPTION |
|---|---|
base_schemas
|
The base rule set.
TYPE:
|
effects
|
The effect instances to lift each base schema under.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple of SchemaDecl
|
The base schemas followed by every lift, grouped by base schema and then by effect. |
Source code in src/quivers/stochastic/effect_lifts.py
Cited sources¶
Conor McBride and Ross Paterson. Applicative programming with effects. Journal of Functional Programming, 18(1):1–13, 2008. URL: https://www.cambridge.org/core/journals/journal-of-functional-programming/article/applicative-programming-with-effects/C80616ACD5687ABDC86D2B341E83D298, doi:10.1017/S0956796807006326.
Philip Wadler. The Essence of Functional Programming. In Proceedings of the 19th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1–14. ACM, 1992. URL: https://doi.org/10.1145/143165.143169, doi:10.1145/143165.143169.