Skip to main content

Nu

Struct Nu 

Source
pub struct Nu<F: HKT, Seed> {
    pub seed: Seed,
    pub coalgebra: Box<dyn Fn(&Seed) -> F::Of<Seed>>,
}
Expand description

The greatest fixed point of a functor F.

Nu<F, Seed> represents a potentially infinite corecursive structure. It stores a seed value and a coalgebra that can observe one layer at a time.

The Seed type parameter is exposed because Rust lacks existential types. This is the same pragmatic compromise used by Lan in karpal-free.

Fields§

§seed: Seed§coalgebra: Box<dyn Fn(&Seed) -> F::Of<Seed>>

Implementations§

Source§

impl<F: HKT, Seed> Nu<F, Seed>

Source

pub fn new( seed: Seed, coalgebra: impl Fn(&Seed) -> F::Of<Seed> + 'static, ) -> Self

Create a Nu from a seed and a coalgebra.

Source

pub fn observe(&self) -> F::Of<Seed>

Apply the coalgebra once to observe one layer.

Source

pub fn to_fix(self) -> Fix<F>
where F: Functor, Seed: Clone,

Convert to Fix<F> by fully unfolding via anamorphism.

This will diverge for truly infinite structures — only call on coalgebras that eventually terminate.

Auto Trait Implementations§

§

impl<F, Seed> Freeze for Nu<F, Seed>
where Seed: Freeze,

§

impl<F, Seed> !RefUnwindSafe for Nu<F, Seed>

§

impl<F, Seed> !Send for Nu<F, Seed>

§

impl<F, Seed> !Sync for Nu<F, Seed>

§

impl<F, Seed> Unpin for Nu<F, Seed>
where Seed: Unpin,

§

impl<F, Seed> UnsafeUnpin for Nu<F, Seed>
where Seed: UnsafeUnpin,

§

impl<F, Seed> !UnwindSafe for Nu<F, Seed>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.