Skip to main content

karpal_arrow/
arrow_loop.rs

1// Copyright (C) 2026 Industrial Algebra
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::arrow::Arrow;
5
6/// ArrowLoop: an Arrow with a loop/fixpoint combinator.
7///
8/// Takes an arrow from `(A, D)` to `(B, D)` and produces an arrow from `A` to `B`,
9/// where `D` is the "feedback" type threaded through the loop.
10///
11/// In Haskell, `loop` relies on laziness to tie the knot. Rust is strict, so
12/// `D: Default` provides the initial feedback seed and the implementation uses
13/// single-pass evaluation.
14pub trait ArrowLoop: Arrow {
15    fn loop_arrow<A: Clone + 'static, B: Clone + 'static, D: Default + Clone + 'static>(
16        f: Self::P<(A, D), (B, D)>,
17    ) -> Self::P<A, B>;
18}