Dedekind 0.0.0
A structuralist C++23 Module Library
Loading...
Searching...
No Matches
dedekind::category::unfold_view< S, Coalg > Class Template Referenceexport
Inheritance diagram for dedekind::category::unfold_view< S, Coalg >:
Collaboration diagram for dedekind::category::unfold_view< S, Coalg >:

Classes

class  iterator
 A position of the walk: the element, the next state, live. More...

Public Types

using element_type
 The elements the walk emits.

Public Member Functions

constexpr unfold_view (S seed, Coalg step)
constexpr iterator begin () const
constexpr std::default_sentinel_t end () const
constexpr S seed () const
constexpr Coalg coalgebra () const

Detailed Description

template<std::regular S, std::semiregular Coalg>
requires std::regular_invocable<const Coalg&, const S&> && requires(std::invoke_result_t<const Coalg&, const S&> y) { { y.has_value() } -> std::same_as<bool>; { y->first }; { y->second } -> std::convertible_to<S>; }
class dedekind::category::unfold_view< S, Coalg >

The anamorphism, and Dedekind's chain

The unfold of a seed by a coalgebra \(S \to 1 + A \times S\): nothing ends the walk, a pair yields an element and the next state. This is the list anamorphism, the lens \([\![(g, p)]\!]\) of Meijer, Fokkinga and Paterson [8], with p the coalgebra yielding nothing: the element where it does is the delimiter and is not emitted. Read against the Jlt paper's Figure 2 (#981): the chain of counts on top, generated by the step and delimited by its fixed point.

| Bananas | here | | the initial algebra of 1 + X | IsNNO, In | | out, by Lambek | Prior, lower_cover | | anamorphism, a lens | unfold; chain, Dedekind's | | catamorphism, a banana | std::ranges::fold_left, cata | | hylomorphism, an envelope | a fold over chain: nothing in between |

The lens here unfolds on the initial algebra: chain walks Lambek's inverse down from a seed and always ends, so Jlt's data-only posture holds by construction. Meijer et al.'s lens into the terminal coalgebra, codata, is a different arrow; it is kept out of the posture, not out of the library (:f_algebra's IsTerminalFCoalgebra; #449). A fold over the chain is the Church-encoded finite sequence, the list as its fold (#1133).

A forward view, O(1) state: the element, its source state, the next state, and whether the walk is live. The coalgebra is a value (Rule 1: semiregular), and two positions of one walk compare by state, so the element need not be comparable.

Template Parameters
Sthe state.
Coalgthe coalgebra, S to optional<pair<A, S>>.

Member Typedef Documentation

◆ element_type

template<std::regular S, std::semiregular Coalg>
using dedekind::category::unfold_view< S, Coalg >::element_type
Initial value:
std::remove_cvref_t<decltype(std::declval<Yield>()->first)>

The elements the walk emits.

Constructor & Destructor Documentation

◆ unfold_view()

template<std::regular S, std::semiregular Coalg>
dedekind::category::unfold_view< S, Coalg >::unfold_view ( S seed,
Coalg step )
inlineconstexpr
Parameters
seedthe first state.
stepthe coalgebra.

Member Function Documentation

◆ begin()

template<std::regular S, std::semiregular Coalg>
iterator dedekind::category::unfold_view< S, Coalg >::begin ( ) const
inlineconstexpr
Returns
the walk, from the seed.

◆ coalgebra()

template<std::regular S, std::semiregular Coalg>
Coalg dedekind::category::unfold_view< S, Coalg >::coalgebra ( ) const
inlineconstexpr
Returns
the coalgebra.

◆ end()

template<std::regular S, std::semiregular Coalg>
std::default_sentinel_t dedekind::category::unfold_view< S, Coalg >::end ( ) const
inlineconstexpr
Returns
the sentinel the walk compares equal to once it has ended.

◆ seed()

template<std::regular S, std::semiregular Coalg>
S dedekind::category::unfold_view< S, Coalg >::seed ( ) const
inlineconstexpr
Returns
the seed.

The documentation for this class was generated from the following file: