Skip to main content

karpal_diagram/
trace.rs

1// Copyright (C) 2026 Industrial Algebra
2// SPDX-License-Identifier: Apache-2.0
3
4#[cfg(any(feature = "std", feature = "alloc"))]
5use karpal_arrow::{ArrowLoop, FnA};
6
7use crate::tensor::Tensor;
8
9/// Traced monoidal structure for closing a feedback wire.
10///
11/// `trace` consumes a morphism `(A, D) -> (B, D)` and hides the feedback
12/// object `D`, yielding a morphism `A -> B`. In Rust's strict evaluation model
13/// this first executable slice follows `ArrowLoop`: `D: Default` supplies the
14/// initial feedback seed for single-pass execution.
15pub trait Trace: Tensor {
16    fn trace<A: Clone + 'static, B: Clone + 'static, D: Default + Clone + 'static>(
17        morphism: Self::P<(A, D), (B, D)>,
18    ) -> Self::P<A, B>;
19}
20
21#[cfg(any(feature = "std", feature = "alloc"))]
22impl Trace for FnA {
23    fn trace<A: Clone + 'static, B: Clone + 'static, D: Default + Clone + 'static>(
24        morphism: Self::P<(A, D), (B, D)>,
25    ) -> Self::P<A, B> {
26        Self::loop_arrow(morphism)
27    }
28}