Skip to main content

Lan

Struct Lan 

Source
pub struct Lan<G, H, A, B>
where G: HKT, H: HKT,
{ /* private fields */ }
Expand description

Left Kan Extension — Lan G H A ≅ ∃B. (G B → A, H B).

Encodes a value H B together with a way to extract A from G B. The intermediate type B is visible in Rust (unlike Haskell’s existential) because Rust lacks first-class existential types.

§Key properties

  • Functor in A: fmap composes onto the extract function, no bounds needed.
  • Specialisation: Lan<IdentityF, F, A, B> is isomorphic to Coyoneda<F, A>.
  • Lower: Given a natural transformation H ~> G, collapse to A.

Implementations§

Source§

impl<G, H, A, B> Lan<G, H, A, B>
where G: HKT + 'static, H: HKT + 'static, A: 'static, B: 'static,

Source

pub fn new( source: <H as HKT>::Of<B>, f: impl Fn(<G as HKT>::Of<B>) -> A + 'static, ) -> Lan<G, H, A, B>

Construct a Lan from a source value and an extract function.

Source

pub fn fmap<C>(self, f: impl Fn(A) -> C + 'static) -> Lan<G, H, C, B>
where C: 'static,

Map a function over the result type. No bounds on G or H required.

Source

pub fn lower<NT>(self) -> A
where NT: NaturalTransformation<H, G>,

Collapse the Lan using a natural transformation NT: H ~> G.

Applies the nat-trans to the source, then extracts the result.

Source§

impl<H, A, B> Lan<IdentityF, H, A, B>
where H: HKT + 'static, A: 'static, B: 'static, <H as HKT>::Of<B>: 'static,

When G = IdentityF, Lan<IdentityF, H, A, B> is isomorphic to Coyoneda<H, A, B>.

Source

pub fn to_coyoneda(self) -> Coyoneda<H, A, B>

Convert to Coyoneda<H, A, B>.

Lan<IdentityF, H, A, B> ≅ (B → A, H B) = Coyoneda<H, A, B>

Auto Trait Implementations§

§

impl<G, H, A, B> !RefUnwindSafe for Lan<G, H, A, B>

§

impl<G, H, A, B> !Send for Lan<G, H, A, B>

§

impl<G, H, A, B> !Sync for Lan<G, H, A, B>

§

impl<G, H, A, B> !UnwindSafe for Lan<G, H, A, B>

§

impl<G, H, A, B> Freeze for Lan<G, H, A, B>
where <H as HKT>::Of<B>: Freeze,

§

impl<G, H, A, B> Unpin for Lan<G, H, A, B>
where <H as HKT>::Of<B>: Unpin, G: Unpin,

§

impl<G, H, A, B> UnsafeUnpin for Lan<G, H, A, B>
where <H as HKT>::Of<B>: UnsafeUnpin,

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.