uor-foundation 0.1.3

UOR Foundation — typed Rust traits for the complete ontology. Import and implement.
Documentation
// @generated by uor-crate from uor-ontology — do not edit manually

//! `stream/` namespace — Coinductive sequences of cascade epochs. Each epoch terminates independently; the stream is the unbounded composition of terminating epochs..
//!
//! Space: Kernel

use crate::Primitives;

/// An unbounded sequence of cascade epochs where each epoch terminates and produces a well-typed output. The coinductive dual of a finite computation.
pub trait ProductiveStream<P: Primitives> {
    /// Always true by construction: every epoch terminates. Invariant, not computed.
    fn is_productive(&self) -> P::Boolean;
}

/// A single bounded iteration within a productive stream. Each epoch is a complete cascade execution from Initialization through Convergence.
pub trait Epoch<P: Primitives> {
    /// Associated type for `EulerCascade`.
    type EulerCascade: crate::kernel::cascade::EulerCascade<P>;
    /// The cascade execution for this epoch.
    fn epoch_cascade(&self) -> &Self::EulerCascade;
    /// Associated type for `Datum`.
    type Datum: crate::kernel::schema::Datum<P>;
    /// The output datum produced by this epoch.
    fn epoch_output(&self) -> &Self::Datum;
    /// Associated type for `Context`.
    type Context: crate::user::state::Context<P>;
    /// The context at the start of this epoch.
    fn epoch_context(&self) -> &Self::Context;
    /// Zero-based index of this epoch in the stream.
    fn epoch_index(&self) -> P::NonNegativeInteger;
}

/// The transition point between consecutive epochs. Carries the continuation context and the epoch output.
pub trait EpochBoundary<P: Primitives> {
    /// Associated type for `Epoch`.
    type Epoch: Epoch<P>;
    /// The epoch that just completed.
    fn boundary_from(&self) -> &Self::Epoch;
    /// The epoch about to begin.
    fn boundary_to(&self) -> &Self::Epoch;
    /// Associated type for `Context`.
    type Context: crate::user::state::Context<P>;
    /// The context carried across the boundary.
    fn continuation_context(&self) -> &Self::Context;
}

/// A finite prefix of a productive stream: the first k epochs and their outputs. Every finite prefix is computable in finite time.
pub trait StreamPrefix<P: Primitives> {
    /// Associated type for `Epoch`.
    type Epoch: Epoch<P>;
    /// The epochs in this prefix (ordered by stream:epochIndex).
    fn prefix_epochs(&self) -> &[Self::Epoch];
    /// Number of epochs in this prefix.
    fn prefix_length(&self) -> P::PositiveInteger;
}

/// A transform between productive streams: maps each epoch of the source to an epoch of the target while preserving the productive property.
pub trait StreamMorphism<P: Primitives>: crate::user::morphism::Transform<P> {}

/// The coinductive constructor: given an initial context and a step function (a morphism:ComputationDatum), produces a ProductiveStream. The step function must be certified to always reach cascade convergence.
pub trait Unfold<P: Primitives> {
    /// Associated type for `Context`.
    type Context: crate::user::state::Context<P>;
    /// The initial context for the stream.
    fn unfold_seed(&self) -> &Self::Context;
    /// Associated type for `ComputationDatum`.
    type ComputationDatum: crate::user::morphism::ComputationDatum<P>;
    /// The certified step function producing each epoch.
    fn unfold_step(&self) -> &Self::ComputationDatum;
    /// Associated type for `ProductiveStream`.
    type ProductiveStream: ProductiveStream<P>;
    /// The stream produced by this unfold.
    fn unfold_result(&self) -> &Self::ProductiveStream;
}