Documentation
¶
Overview ¶
Package cove carries explicit ambient context across kont suspension boundaries.
When a runtime advances a kont computation one suspension at a time, each suspended operation may depend on state that lives outside the operation itself, such as dispatch budget, ring capabilities, protocol phase, or buffer-group validity. cove pairs that context with values and suspensions so it stays explicit across asynchronous boundaries instead of travelling through hidden globals or ad-hoc side maps.
Read through the lens of modal effects, the carrier shape can be read as naming what happens to ambient context: kont (C → D) replaces it, cove (W(C, A) → B) handles it relatively, and pure pass-through preserves it. Effect structure rides on the carrier, not on a function colour, which keeps cove policy-free.
Responsibilities stay split by layer:
- code.hybscloud.com/iox classifies outcome and progress evidence
- kont defines suspension and resumption shape
- cove carries and checks explicit context
- code.hybscloud.com/takt advances execution without taking ownership of that context
The package is policy-free: it carries and checks context but never schedules, retries, or dispatches. Kernel mechanics belong to uring, and semantic outcome branching belongs to iox, including code.hybscloud.com/iox.Classify. The join point with takt is structural: a contextual carrier exposes the current suspended operation and accepts the matching resumption without transferring ownership of the context to the runner.
Carriers:
- [View[C, A]], a focused value paired with ambient context
- [Cmd[C, A, B]], a contextual command over View
- [SuspensionView[C, A]], a kont.Suspension paired with ambient context
- World, StepIndex, [Preorder[C]], [Transition[C]], [Forcing[C]], [ForcingExpr[C]], [Indexed[C, A]], and [Relation[C, A]], step-indexed Kripke evidence over ambient worlds
- [IndexedView[C, A]] and [IndexedSuspensionView[C, A]], contextual observations paired with explicit finite step credit
- [Req[C]] / [ReqExpr[C]], context predicates in closure and data forms
- [Rule[C]] / [RuleExpr[C]] with Report, named predicates for diagnostics
- [Checked[C, A]] / [CheckedExpr[C, A]], requirement-gated values
- [Guarded[C, A]] / [GuardedExpr[C, A]], rule-gated values
Commands:
- ExtractCmd returns the focused value as the identity contextual command
- LiftCmd lifts a focus-only transform into a contextual command
- Compose composes contextual commands through Extend
- Run applies a command to a concrete View
Contextual suspension boundary:
- StepWith / StepExprWith run a kont computation and pair its first suspension with context
- StepWithIndex / StepExprWithIndex do the same with explicit step credit
- MapContextSuspension / WithContextSuspension map or replace carried context explicitly
- SuspensionView.Op / SuspensionView.Resume expose the structural join point consumed by takt
- SuspensionView.ResumeWith advances a suspension and evolves context for the next step
- IndexedSuspensionView.ResumeWith additionally decrements the step index
- IndexedSuspensionView.ResumeTo decrements the index and checks monotone world extension
- CheckSuspension / CheckSuspensionExpr gate contextualization on a requirement
Kripke structure:
- World names the Kripke reading of ambient context
- [Preorder[C]] names world extension, w <= w'
- DiscreteWorlds and TotalWorlds provide equality-only and total preorders
- Extends is the package-level world-extension helper
- Preorder.Extends, Preorder.ReflexiveAt, and Preorder.TransitiveAt expose concrete preorder law checks
- [Transition[C]], CheckTransition, CheckForcingTransition, and CheckInvariantTransition check concrete world edges
- Force / ForceExpr construct [Forcing[C]] and [ForcingExpr[C]] evidence with monotonicity checks
- [Relation[C, A]] is indexed by world, StepIndex, and value
- Later implements the guarded later modality: index zero is trivial; index n+1 checks at n
- CheckRelation, WeakenIndexedView, and WeakenIndexedSuspension check indexed evidence or weaken finite credit
- CheckCompletedRelation checks the final finite-trace relation at a completed indexed frontier
Nil-completion convention: cove forwards kont's stepping classifier, so Step, StepExpr, StepWith, StepExprWith, SuspensionView.Resume, and SuspensionView.ResumeWith report completion by yielding no further suspension frontier (a nil *kont.Suspension, or a SuspensionView whose [SuspensionView.Suspension] field is nil). The completed payload returned in that case is the zero value of A. Suspended steps may also return the zero value of A, so callers must use the suspension/frontier result—not A itself, and for SuspensionView specifically its [SuspensionView.Suspension] field—to detect completion. Computations whose result type A is a nilable type (pointer, interface, map, slice, channel, or function) therefore cannot use nil as a meaningful completed value; wrap nil in an explicit sum or witness type when that distinction matters. Carrier context is unaffected: SuspensionView.Ask still returns the ambient context after completion.
Bridge helpers:
- Step, StepExpr, Reify, Reflect, ReifyReq, and ReflectReq remain available as convenience wrappers around kont
Laws:
- Duplicate(v).Extract() == v
- Extend(v, func(w View[C, A]) A { return w.Extract() }) == v
- Compose(g, f)(v) == g(Extend(v, f))
- Compose(ExtractCmd, f) == f and Compose(g, ExtractCmd) == g
- NeedExpr(ctx, ReifyReq(req)) == Need(ctx, req), when req != nil
- Need(ctx, ReflectReq(expr)) == NeedExpr(ctx, expr)
- ExprPullback distributes over ExprNot, ExprAll, and ExprAny
Index ¶
- func CheckCompletedRelation[C World, A Focus](v IndexedSuspensionView[C, A], value A, r Relation[C, A]) bool
- func CheckForcingTransition[C World](f Forcing[C], t Transition[C]) bool
- func CheckInvariantTransition[C World](leq Preorder[C], req Req[C], t Transition[C]) bool
- func CheckRelation[C World, A Focus](v IndexedView[C, A], r Relation[C, A]) bool
- func CheckTransition[C World](leq Preorder[C], t Transition[C]) bool
- func Extends[C World](leq Preorder[C], w, wNext C) bool
- func ExtractCmd[C Ambient, A Focus](v View[C, A]) A
- func Need[C Ambient](ctx C, req Req[C]) bool
- func NeedExpr[C Ambient](ctx C, req ReqExpr[C]) bool
- func Reflect[A Focus](m kont.Expr[A]) kont.Cont[Resumed, A]
- func Reify[A Focus](m kont.Cont[Resumed, A]) kont.Expr[A]
- func Run[C Ambient, A, B Focus](v View[C, A], cmd Cmd[C, A, B]) B
- func Step[A Focus](m kont.Cont[Resumed, A]) (A, *kont.Suspension[A])
- func StepExpr[A Focus](m kont.Expr[A]) (A, *kont.Suspension[A])
- type Ambient
- type Checked
- type CheckedExpr
- type Cmd
- type Focus
- type Forcing
- type ForcingExpr
- type Guarded
- type GuardedExpr
- type Indexed
- type IndexedSuspensionView
- func ObserveIndexedSuspension[C World, A Focus](ctx C, index StepIndex, susp *kont.Suspension[A]) IndexedSuspensionView[C, A]
- func StepExprWithIndex[C World, A Focus](ctx C, index StepIndex, m kont.Expr[A]) (A, IndexedSuspensionView[C, A])
- func StepWithIndex[C World, A Focus](ctx C, index StepIndex, m kont.Cont[Resumed, A]) (A, IndexedSuspensionView[C, A])
- func WeakenIndexedSuspension[C World, A Focus](v IndexedSuspensionView[C, A], target StepIndex) (IndexedSuspensionView[C, A], bool)
- func (v IndexedSuspensionView[C, A]) Ask() C
- func (v IndexedSuspensionView[C, A]) Completed() bool
- func (v IndexedSuspensionView[C, A]) Discard()
- func (v IndexedSuspensionView[C, A]) Extract() *kont.Suspension[A]
- func (v IndexedSuspensionView[C, A]) Op() Operation
- func (v IndexedSuspensionView[C, A]) Resume(value Resumed) (A, IndexedSuspensionView[C, A])
- func (v IndexedSuspensionView[C, A]) ResumeTo(leq Preorder[C], value Resumed, nextWorld C) (A, IndexedSuspensionView[C, A])
- func (v IndexedSuspensionView[C, A]) ResumeWith(value Resumed, f func(C) C) (A, IndexedSuspensionView[C, A])
- type IndexedView
- type Operation
- type Preorder
- type Relation
- type Report
- type Req
- type ReqExpr
- func ExprAll[C Ambient](reqs ...ReqExpr[C]) ReqExpr[C]
- func ExprAny[C Ambient](reqs ...ReqExpr[C]) ReqExpr[C]
- func ExprAtom[C Ambient](fn func(C) bool) ReqExpr[C]
- func ExprFalse[C Ambient]() ReqExpr[C]
- func ExprNot[C Ambient](inner ReqExpr[C]) ReqExpr[C]
- func ExprPullback[C, D Ambient](req ReqExpr[D], f func(C) D) ReqExpr[C]
- func ExprTrue[C Ambient]() ReqExpr[C]
- func ReifyReq[C Ambient](req Req[C]) ReqExpr[C]
- type Resumed
- type Rule
- type RuleError
- type RuleExpr
- type StepIndex
- type SuspensionView
- func CheckSuspension[C Ambient, A Focus](ctx C, susp *kont.Suspension[A], req Req[C]) (SuspensionView[C, A], bool)
- func CheckSuspensionExpr[C Ambient, A Focus](ctx C, susp *kont.Suspension[A], req ReqExpr[C]) (SuspensionView[C, A], bool)
- func MapContextSuspension[C, D Ambient, A Focus](v SuspensionView[C, A], f func(C) D) SuspensionView[D, A]
- func ObserveSuspension[C Ambient, A Focus](ctx C, susp *kont.Suspension[A]) SuspensionView[C, A]
- func StepExprWith[C Ambient, A Focus](ctx C, m kont.Expr[A]) (A, SuspensionView[C, A])
- func StepWith[C Ambient, A Focus](ctx C, m kont.Cont[Resumed, A]) (A, SuspensionView[C, A])
- func WithContextSuspension[C Ambient, A Focus](v SuspensionView[C, A], ctx C) SuspensionView[C, A]
- func (v SuspensionView[C, A]) Ask() C
- func (v SuspensionView[C, A]) Discard()
- func (v SuspensionView[C, A]) Extract() *kont.Suspension[A]
- func (v SuspensionView[C, A]) Op() Operation
- func (v SuspensionView[C, A]) Resume(value Resumed) (A, SuspensionView[C, A])
- func (v SuspensionView[C, A]) ResumeWith(value Resumed, f func(C) C) (A, SuspensionView[C, A])
- type Transition
- type View
- func Duplicate[C Ambient, A Focus](v View[C, A]) View[C, View[C, A]]
- func Extend[C Ambient, A, B Focus](v View[C, A], f func(View[C, A]) B) View[C, B]
- func Map[C Ambient, A, B Focus](v View[C, A], f func(A) B) View[C, B]
- func MapContext[C, D Ambient, A Focus](v View[C, A], f func(C) D) View[D, A]
- func Observe[C Ambient, A Focus](ctx C, value A) View[C, A]
- func Replace[C Ambient, A, B Focus](v View[C, A], value B) View[C, B]
- func WithContext[C Ambient, A Focus](v View[C, A], ctx C) View[C, A]
- type World
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckCompletedRelation ¶ added in v0.1.2
func CheckCompletedRelation[C World, A Focus](v IndexedSuspensionView[C, A], value A, r Relation[C, A]) bool
CheckCompletedRelation checks the finite-trace adequacy bridge for a completed indexed suspension frontier.
It reports false while the frontier is still suspended. After completion, it checks whether value is in r at the frontier's final world and remaining step index.
func CheckForcingTransition ¶ added in v0.1.2
func CheckForcingTransition[C World](f Forcing[C], t Transition[C]) bool
CheckForcingTransition checks that a concrete transition extends the world and preserves f at both endpoints.
func CheckInvariantTransition ¶ added in v0.1.2
func CheckInvariantTransition[C World](leq Preorder[C], req Req[C], t Transition[C]) bool
CheckInvariantTransition checks that req holds across a concrete transition under leq.
func CheckRelation ¶ added in v0.1.2
func CheckRelation[C World, A Focus](v IndexedView[C, A], r Relation[C, A]) bool
CheckRelation reports whether v satisfies r at its carried world and index.
func CheckTransition ¶ added in v0.1.2
func CheckTransition[C World](leq Preorder[C], t Transition[C]) bool
CheckTransition reports whether t.After is an admissible successor of t.Before under leq.
func Extends ¶ added in v0.1.2
Extends reports whether wNext is an admissible future refinement of w.
func ExtractCmd ¶ added in v0.1.0
ExtractCmd returns the focused value and serves as the identity command for View: Compose(ExtractCmd, f) == f and Compose(g, ExtractCmd) == g.
func Reflect ¶
Reflect converts a kont.Expr computation to kont.Cont. Prefer StepWith or StepExprWith when the caller needs the contextual suspension boundary.
func Reify ¶
Reify converts a kont.Cont computation to kont.Expr. Prefer StepWith or StepExprWith when the caller needs the contextual suspension boundary.
func Step ¶
Step re-exports kont.Step. Prefer StepWith when the suspension should remain paired with explicit context. As with kont.Step, a nil suspension result denotes completion; the returned A follows kont's nil-completion convention (a nil payload becomes the zero value of A).
func StepExpr ¶
func StepExpr[A Focus](m kont.Expr[A]) (A, *kont.Suspension[A])
StepExpr re-exports kont.StepExpr. Prefer StepExprWith when the suspension should remain paired with explicit context. As with kont.StepExpr, a nil suspension result denotes completion; the returned A follows kont's nil-completion convention (a nil payload becomes the zero value of A).
Types ¶
type Checked ¶
Checked pairs a value with a requirement.
func MapChecked ¶
MapChecked maps the value and preserves the requirement.
func PullbackChecked ¶
PullbackChecked transports c along a context projection.
type CheckedExpr ¶
CheckedExpr pairs a value with a requirement expression.
func GuardExpr ¶
func GuardExpr[C Ambient, A Focus](req ReqExpr[C], value A) CheckedExpr[C, A]
GuardExpr constructs a checked value from a requirement expression.
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
)
func main() {
type runtime struct{ Budget int }
checked := cove.GuardExpr(
cove.ExprAtom(func(r runtime) bool { return r.Budget > 0 }),
"payload",
)
view, ok := checked.IntoView(runtime{Budget: 2})
fmt.Println(ok, view.Extract())
_, ok = checked.IntoView(runtime{Budget: 0})
fmt.Println(ok)
}
Output: true payload false
func MapCheckedExpr ¶
func MapCheckedExpr[C Ambient, A, B Focus](c CheckedExpr[C, A], f func(A) B) CheckedExpr[C, B]
MapCheckedExpr maps the value and preserves the requirement.
func PullbackCheckedExpr ¶
func PullbackCheckedExpr[C, D Ambient, A Focus](checked CheckedExpr[C, A], f func(D) C) CheckedExpr[D, A]
PullbackCheckedExpr transports c along a context projection.
func (CheckedExpr[C, A]) Check ¶
func (c CheckedExpr[C, A]) Check(ctx C) bool
Check reports whether ctx satisfies c's requirement.
func (CheckedExpr[C, A]) IntoView ¶
func (c CheckedExpr[C, A]) IntoView(ctx C) (View[C, A], bool)
IntoView returns a view when c's requirement holds.
func (CheckedExpr[C, A]) MustView ¶
func (c CheckedExpr[C, A]) MustView(ctx C) View[C, A]
MustView returns a view and panics if c's requirement does not hold.
type Cmd ¶ added in v0.1.0
Cmd is the coKleisli arrow for View: it consumes a contextual observation and produces a focus result without hiding the ambient context.
type Forcing ¶ added in v0.1.2
type Forcing[C World] struct { // contains filtered or unexported fields }
Forcing is a requirement together with the world preorder under which the requirement must be monotone.
func Force ¶ added in v0.1.2
Force constructs forcing evidence over a world preorder.
The caller supplies the predicate and the preorder; Forcing.MonotoneAt checks the monotonicity obligation at concrete world pairs.
func (Forcing[C]) MonotoneAt ¶ added in v0.1.2
MonotoneAt checks the forcing monotonicity obligation at w <= wNext.
The law is: if w <= wNext and f holds at w, then f holds at wNext.
type ForcingExpr ¶ added in v0.1.2
type ForcingExpr[C World] struct { // contains filtered or unexported fields }
ForcingExpr is the ReqExpr counterpart of Forcing.
func ForceExpr ¶ added in v0.1.2
func ForceExpr[C World](leq Preorder[C], req ReqExpr[C]) ForcingExpr[C]
ForceExpr constructs expression-form forcing evidence over a world preorder.
func (ForcingExpr[C]) Holds ¶ added in v0.1.2
func (f ForcingExpr[C]) Holds(world C) bool
Holds reports whether world satisfies f.
func (ForcingExpr[C]) MonotoneAt ¶ added in v0.1.2
func (f ForcingExpr[C]) MonotoneAt(w, wNext C) bool
MonotoneAt checks expression-form forcing monotonicity at w <= wNext.
func (ForcingExpr[C]) Preorder ¶ added in v0.1.2
func (f ForcingExpr[C]) Preorder() Preorder[C]
Preorder returns the world-extension relation carried by f.
func (ForcingExpr[C]) Req ¶ added in v0.1.2
func (f ForcingExpr[C]) Req() ReqExpr[C]
Req returns the underlying expression requirement.
type Guarded ¶
Guarded pairs a value with a named rule.
func MapGuarded ¶
MapGuarded maps the value and preserves the rule.
func PullbackGuarded ¶
PullbackGuarded transports g along a context projection.
type GuardedExpr ¶
GuardedExpr pairs a value with a named requirement expression.
func GuardRuleExpr ¶
func GuardRuleExpr[C Ambient, A Focus](rule RuleExpr[C], value A) GuardedExpr[C, A]
GuardRuleExpr constructs a guarded value from a rule expression.
func MapGuardedExpr ¶
func MapGuardedExpr[C Ambient, A, B Focus](g GuardedExpr[C, A], f func(A) B) GuardedExpr[C, B]
MapGuardedExpr maps the value and preserves the rule.
func PullbackGuardedExpr ¶
func PullbackGuardedExpr[C, D Ambient, A Focus](guarded GuardedExpr[C, A], f func(D) C) GuardedExpr[D, A]
PullbackGuardedExpr transports g along a context projection.
func (GuardedExpr[C, A]) Check ¶
func (g GuardedExpr[C, A]) Check(ctx C) Report
Check checks the guarded rule against ctx.
func (GuardedExpr[C, A]) IntoView ¶
func (g GuardedExpr[C, A]) IntoView(ctx C) (View[C, A], Report)
IntoView returns a view together with the rule report.
type Indexed ¶ added in v0.1.2
Indexed is a step-indexed predicate over world, approximation level, and value.
type IndexedSuspensionView ¶ added in v0.1.2
type IndexedSuspensionView[C World, A Focus] struct { Index StepIndex View SuspensionView[C, A] }
IndexedSuspensionView pairs a contextual suspension with explicit step fuel.
func ObserveIndexedSuspension ¶ added in v0.1.2
func ObserveIndexedSuspension[C World, A Focus](ctx C, index StepIndex, susp *kont.Suspension[A]) IndexedSuspensionView[C, A]
ObserveIndexedSuspension returns an indexed suspension view.
func StepExprWithIndex ¶ added in v0.1.2
func StepExprWithIndex[C World, A Focus](ctx C, index StepIndex, m kont.Expr[A]) (A, IndexedSuspensionView[C, A])
StepExprWithIndex runs an Expr computation and pairs its first suspension with ctx and an explicit step index.
func StepWithIndex ¶ added in v0.1.2
func StepWithIndex[C World, A Focus](ctx C, index StepIndex, m kont.Cont[Resumed, A]) (A, IndexedSuspensionView[C, A])
StepWithIndex runs a Cont computation and pairs its first suspension with ctx and an explicit step index.
func WeakenIndexedSuspension ¶ added in v0.1.2
func WeakenIndexedSuspension[C World, A Focus](v IndexedSuspensionView[C, A], target StepIndex) (IndexedSuspensionView[C, A], bool)
WeakenIndexedSuspension returns v observed at target when target is a valid weakening of v's current step index.
func (IndexedSuspensionView[C, A]) Ask ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) Ask() C
Ask returns the ambient context.
func (IndexedSuspensionView[C, A]) Completed ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) Completed() bool
Completed reports whether the indexed suspension frontier has completed.
func (IndexedSuspensionView[C, A]) Discard ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) Discard()
Discard consumes the underlying suspension without resuming it.
func (IndexedSuspensionView[C, A]) Extract ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) Extract() *kont.Suspension[A]
Extract returns the underlying suspension.
func (IndexedSuspensionView[C, A]) Op ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) Op() Operation
Op returns the suspended operation.
func (IndexedSuspensionView[C, A]) Resume ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) Resume(value Resumed) (A, IndexedSuspensionView[C, A])
Resume advances the suspension and consumes one step of fuel. It panics if the suspension has completed or if the step index is zero.
func (IndexedSuspensionView[C, A]) ResumeTo ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) ResumeTo(leq Preorder[C], value Resumed, nextWorld C) (A, IndexedSuspensionView[C, A])
ResumeTo advances the suspension to a specified successor world.
It consumes one step of fuel and requires nextWorld to extend the current world under leq. Use ResumeTo when the indexed observation is intended as Kripke evidence; use ResumeWith only for policy-free context threading where the caller proves monotonicity externally. It panics if the suspension has completed, if the step index is zero, or if nextWorld does not extend the current world under leq.
func (IndexedSuspensionView[C, A]) ResumeWith ¶ added in v0.1.2
func (v IndexedSuspensionView[C, A]) ResumeWith(value Resumed, f func(C) C) (A, IndexedSuspensionView[C, A])
ResumeWith advances the suspension, consumes one step of fuel, and evolves the carried world for the successor observation. It panics if the suspension has completed or if the step index is zero.
type IndexedView ¶ added in v0.1.2
IndexedView pairs a contextual value with an explicit step index.
func ObserveIndexed ¶ added in v0.1.2
func ObserveIndexed[C World, A Focus](ctx C, index StepIndex, value A) IndexedView[C, A]
ObserveIndexed returns an indexed view for ctx, index, and value.
func WeakenIndexedView ¶ added in v0.1.2
func WeakenIndexedView[C World, A Focus](v IndexedView[C, A], target StepIndex) (IndexedView[C, A], bool)
WeakenIndexedView returns v observed at target when target is a valid weakening of v's current step index.
func (IndexedView[C, A]) Ask ¶ added in v0.1.2
func (v IndexedView[C, A]) Ask() C
Ask returns the ambient context.
func (IndexedView[C, A]) Extract ¶ added in v0.1.2
func (v IndexedView[C, A]) Extract() A
Extract returns the focused value.
type Preorder ¶ added in v0.1.2
Preorder is the Kripke world-extension relation on ambient contexts.
A call leq(w, wNext) means w <= wNext: wNext is an admissible future refinement of w.
func DiscreteWorlds ¶ added in v0.1.2
func DiscreteWorlds[C comparable]() Preorder[C]
DiscreteWorlds returns equality as a world preorder for comparable contexts.
func TotalWorlds ¶ added in v0.1.2
TotalWorlds returns the preorder where every world refines every other world.
func (Preorder[C]) Extends ¶ added in v0.1.2
Extends reports whether wNext is an admissible future refinement of w.
func (Preorder[C]) ReflexiveAt ¶ added in v0.1.2
ReflexiveAt checks the preorder reflexivity law at w.
func (Preorder[C]) TransitiveAt ¶ added in v0.1.2
TransitiveAt checks the preorder transitivity law at w0 <= w1 <= w2.
type Relation ¶ added in v0.1.2
Relation is a step-indexed Kripke logical relation over contextual values.
func Later ¶ added in v0.1.2
Later delays r by one physical step.
At index zero, Later is guarded and holds trivially. At n+1, it checks r at n.
func (Relation[C, A]) Holds ¶ added in v0.1.2
Holds reports whether value belongs to r at world and index.
func (Relation[C, A]) MonotoneAt ¶ added in v0.1.2
MonotoneAt checks Kripke monotonicity at w <= wNext for a fixed index.
type Report ¶
type Report struct {
Failed RuleError // zero value means success
Checked int // number of rules examined before success or first failure
}
Report records the result of checking one or more named rules.
func CheckRuleExpr ¶
CheckRuleExpr checks a single rule expression.
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
)
func main() {
type runtime struct{ Budget int }
rule := cove.RequireExpr("budget", cove.ExprAtom(func(r runtime) bool {
return r.Budget > 0
}))
report := cove.CheckRuleExpr(runtime{Budget: 5}, rule)
fmt.Println(report.OK())
report = cove.CheckRuleExpr(runtime{Budget: 0}, rule)
fmt.Println(report.OK(), report.Failed)
}
Output: true false budget
func CheckRules ¶
CheckRules checks rules from left to right and stops at the first failure.
func CheckRulesExpr ¶
CheckRulesExpr checks rule expressions from left to right and stops at the first failure.
func (Report) Err ¶ added in v0.1.0
Err returns the first failed rule as an error, or nil on success.
func (Report) FailedRule ¶ added in v0.1.0
FailedRule reports the first failed rule label, or "" on success.
For direct Rule literals with an empty name, the label falls back to "cove: unnamed rule".
type Req ¶
Req is a requirement over ambient context C.
func All ¶
All returns the conjunction of reqs.
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
)
func main() {
type caps struct {
CanSubmit bool
HasToken bool
}
req := cove.All(
func(c caps) bool { return c.CanSubmit },
func(c caps) bool { return c.HasToken },
)
fmt.Println(cove.Need(caps{CanSubmit: true, HasToken: true}, req))
}
Output: true
func Pullback ¶
Pullback transports req along a context projection.
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
)
func main() {
type runtime struct{ Budget int }
req := cove.Pullback(func(budget int) bool { return budget > 0 }, func(rt runtime) int {
return rt.Budget
})
fmt.Println(cove.Need(runtime{Budget: 2}, req))
}
Output: true
func ReflectReq ¶
ReflectReq returns a closure-form requirement that delegates to NeedExpr. It preserves the observable predicate, but once converted back to Req the original Expr structure is no longer recoverable from the closure alone.
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
)
func main() {
type runtime struct {
Budget int
CanDispatch bool
}
expr := cove.ExprAll(
cove.ExprAtom(func(r runtime) bool { return r.Budget > 0 }),
cove.ExprAtom(func(r runtime) bool { return r.CanDispatch }),
)
req := cove.ReflectReq(expr)
ctx := runtime{Budget: 2, CanDispatch: true}
fmt.Println(cove.NeedExpr(ctx, expr))
fmt.Println(cove.Need(ctx, req))
}
Output: true true
type ReqExpr ¶
type ReqExpr[C Ambient] struct { // contains filtered or unexported fields }
ReqExpr stores a requirement as data instead of a closure. The zero value is ExprTrue.
func ExprPullback ¶
ExprPullback transports req along a context projection and preserves its explicit Boolean structure.
func ReifyReq ¶
ReifyReq wraps a closure-form Req as an ExprAtom. It is a lossy quotation helper for bridging into Expr-world composition, not a structural inverse of ReflectReq. In particular, ReifyReq(nil) is invalid and panics when the resulting expression is evaluated through NeedExpr.
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
)
func main() {
req := cove.Req[int](func(v int) bool { return v > 0 })
expr := cove.ReifyReq(req)
fmt.Println(cove.NeedExpr(1, expr))
fmt.Println(cove.NeedExpr(-1, expr))
}
Output: true false
type Rule ¶
Rule names a requirement for diagnostics.
func PullbackRule ¶
PullbackRule transports r along a context projection.
type RuleExpr ¶
RuleExpr names a requirement expression for diagnostics.
func PullbackRuleExpr ¶
PullbackRuleExpr transports r along a context projection.
func RequireExpr ¶
RequireExpr constructs a named requirement expression for diagnostics.
type StepIndex ¶ added in v0.1.2
StepIndex is the finite approximation level used by step-indexed contextual interpretations.
type SuspensionView ¶
type SuspensionView[C Ambient, A Focus] struct { Ctx C Suspension *kont.Suspension[A] }
SuspensionView pairs a kont.Suspension with ambient context. Its Op and Resume methods keep the carrier structurally joinable with `takt` without transferring ownership of the carried context to the runner. A nil Suspension means the computation has completed; Op, Resume, ResumeWith, and Discard panic after completion.
func CheckSuspension ¶
func CheckSuspension[C Ambient, A Focus](ctx C, susp *kont.Suspension[A], req Req[C]) (SuspensionView[C, A], bool)
CheckSuspension returns a suspension view when req holds.
func CheckSuspensionExpr ¶
func CheckSuspensionExpr[C Ambient, A Focus](ctx C, susp *kont.Suspension[A], req ReqExpr[C]) (SuspensionView[C, A], bool)
CheckSuspensionExpr returns a suspension view when req holds in expression form.
func MapContextSuspension ¶ added in v0.1.0
func MapContextSuspension[C, D Ambient, A Focus](v SuspensionView[C, A], f func(C) D) SuspensionView[D, A]
MapContextSuspension maps the ambient context and preserves the observed suspension frontier.
func ObserveSuspension ¶
func ObserveSuspension[C Ambient, A Focus](ctx C, susp *kont.Suspension[A]) SuspensionView[C, A]
ObserveSuspension returns a suspension view for ctx and susp.
func StepExprWith ¶
func StepExprWith[C Ambient, A Focus](ctx C, m kont.Expr[A]) (A, SuspensionView[C, A])
StepExprWith runs an Expr computation and pairs its first suspension with ctx. It is the primary contextual stepping entry point for callers already in Expr form. Completion is observed when the returned [SuspensionView.Suspension] is nil; in that case, the result A follows kont's nil-completion convention (nilable types cannot use nil as a meaningful completed payload without an explicit witness).
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
"code.hybscloud.com/kont"
)
func main() {
type runtime struct{ Budget int }
type ping struct{ kont.Phantom[int] }
expr := kont.ExprBind(kont.ExprPerform(ping{}), func(v int) kont.Expr[int] {
return kont.ExprReturn(v + 1)
})
_, step := cove.StepExprWith(runtime{Budget: 2}, expr)
fmt.Println(step.Suspension != nil)
fmt.Println(step.Ask().Budget)
_, isPing := step.Op().(ping)
fmt.Println(isPing)
result, sv := step.Resume(41)
fmt.Println(result, sv.Suspension != nil)
}
Output: true 2 true 42 false
func StepWith ¶
StepWith runs a Cont computation and pairs its first suspension with ctx. It is the primary contextual stepping entry point. Completion is observed when the returned [SuspensionView.Suspension] is nil; in that case, the result A follows kont's nil-completion convention (nilable types cannot use nil as a meaningful completed payload without an explicit witness).
func WithContextSuspension ¶ added in v0.1.0
func WithContextSuspension[C Ambient, A Focus](v SuspensionView[C, A], ctx C) SuspensionView[C, A]
WithContextSuspension replaces the ambient context and preserves the observed suspension frontier.
func (SuspensionView[C, A]) Ask ¶
func (v SuspensionView[C, A]) Ask() C
Ask returns the ambient context.
func (SuspensionView[C, A]) Discard ¶
func (v SuspensionView[C, A]) Discard()
Discard consumes the suspension without resuming it. It panics after completion.
func (SuspensionView[C, A]) Extract ¶
func (v SuspensionView[C, A]) Extract() *kont.Suspension[A]
Extract returns the underlying suspension.
func (SuspensionView[C, A]) Op ¶
func (v SuspensionView[C, A]) Op() Operation
Op returns the suspended operation. It panics after completion.
func (SuspensionView[C, A]) Resume ¶
func (v SuspensionView[C, A]) Resume(value Resumed) (A, SuspensionView[C, A])
Resume advances the suspension and keeps the current context. When the resumed computation completes, the returned value follows kont's nil-completion convention: a nil completed payload becomes the zero value of A. Callers must use the returned SuspensionView (which has a nil suspension on completion) to detect completion, rather than testing the value of A. It panics after completion.
func (SuspensionView[C, A]) ResumeWith ¶
func (v SuspensionView[C, A]) ResumeWith(value Resumed, f func(C) C) (A, SuspensionView[C, A])
ResumeWith advances the suspension and optionally maps the context for the next step. When the resumed computation completes, the returned value follows kont's nil-completion convention: a nil completed payload becomes the zero value of A. Callers must use the returned SuspensionView (which has a nil suspension on completion) to detect completion, rather than testing the value of A. It panics after completion. A nil mapper keeps the current context, so ResumeWith strictly generalizes [Resume].
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
"code.hybscloud.com/kont"
)
func main() {
type runtime struct {
Budget int
kont.Phantom[int]
}
type ping struct{ kont.Phantom[int] }
expr := kont.ExprBind(kont.ExprPerform(ping{}), func(v int) kont.Expr[int] {
return kont.ExprReturn(v + 1)
})
_, step := cove.StepExprWith(runtime{Budget: 10}, expr)
fmt.Println(step.Ask().Budget)
result, sv := step.ResumeWith(41, func(r runtime) runtime {
r.Budget--
return r
})
fmt.Println(result, sv.Suspension != nil)
}
Output: 10 42 false
type Transition ¶ added in v0.1.2
type Transition[C World] struct { Before C After C }
Transition is a concrete candidate edge between two Kripke worlds.
type View ¶
View represents a focused value under ambient context.
func Extend ¶
Extend applies f to the whole view and preserves the ambient context. Together with [Extract] and Duplicate, it defines the core view operations.
Example ¶
package main
import (
"fmt"
"code.hybscloud.com/cove"
)
func main() {
type ctx struct{ Budget int }
v := cove.Observe(ctx{Budget: 4}, 10)
next := cove.Extend(v, func(v cove.View[ctx, int]) int {
return v.Value + v.Ctx.Budget
})
fmt.Println(next.Extract())
}
Output: 14
func MapContext ¶
MapContext maps the ambient context and preserves the focused value.
func WithContext ¶
WithContext substitutes the ambient context and preserves the focused value.