Skip to main content

Coend

Struct Coend 

Source
pub struct Coend<P, A>
where P: HKT2,
{ pub value: <P as HKT2>::P<A, A>, }
Expand description

A Coend for profunctor P: represents ∫^A P(A, A), i.e., exists A. P(A, A).

In category theory, the coend of a profunctor P: C^op × C -> Set is the universal cowedge — a value P(A, A) for SOME (existentially hidden) type A.

Since Rust lacks first-class existential types, the type parameter A is exposed (following the same pragmatic approach as Lan<G, H, A, B> in karpal-free). Users should treat A as opaque when consuming coend values.

§Construction

use karpal_core::coend::Coend;
use karpal_core::hkt::TupleF;

// A coend value: exists some A such that we have (A, A)
let c: Coend<TupleF, i32> = Coend::new((42, 42));
assert_eq!(c.value, (42, 42));

Fields§

§value: <P as HKT2>::P<A, A>

The diagonal value P(A, A) for the existentially quantified A.

Implementations§

Source§

impl<P, A> Coend<P, A>
where P: HKT2,

Source

pub fn new(value: <P as HKT2>::P<A, A>) -> Coend<P, A>

Construct a coend value from a diagonal element.

Source

pub fn elim<R>(self, f: impl FnOnce(<P as HKT2>::P<A, A>) -> R) -> R

Eliminate the coend by applying a function to the diagonal value.

Given a function P(A, A) -> R, extract a result. This is the concrete elimination form — in category theory, the eliminator would be a dinatural transformation, but here the type parameter A is exposed rather than existentially hidden.

Trait Implementations§

Source§

impl<P, A> Clone for Coend<P, A>
where P: HKT2, A: Clone, <P as HKT2>::P<A, A>: Clone,

Source§

fn clone(&self) -> Coend<P, A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P, A> Debug for Coend<P, A>
where P: HKT2, A: Debug, <P as HKT2>::P<A, A>: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<P, A> Eq for Coend<P, A>
where P: HKT2, A: Eq, <P as HKT2>::P<A, A>: Eq,

Source§

impl<P, A> PartialEq for Coend<P, A>
where P: HKT2, A: PartialEq, <P as HKT2>::P<A, A>: PartialEq,

Source§

fn eq(&self, other: &Coend<P, A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<P, A> Freeze for Coend<P, A>
where <P as HKT2>::P<A, A>: Freeze,

§

impl<P, A> RefUnwindSafe for Coend<P, A>
where <P as HKT2>::P<A, A>: RefUnwindSafe,

§

impl<P, A> Send for Coend<P, A>
where <P as HKT2>::P<A, A>: Send,

§

impl<P, A> Sync for Coend<P, A>
where <P as HKT2>::P<A, A>: Sync,

§

impl<P, A> Unpin for Coend<P, A>
where <P as HKT2>::P<A, A>: Unpin,

§

impl<P, A> UnsafeUnpin for Coend<P, A>
where <P as HKT2>::P<A, A>: UnsafeUnpin,

§

impl<P, A> UnwindSafe for Coend<P, A>
where <P as HKT2>::P<A, A>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.