Trait naan::Equiv

source ·
pub trait Equiv {
    type To;
}
Expand description

An Equiv type is one that is conceptually the same as some different type.

This is used to allow types to implement typeclasses for other types in a still strict way. For examples see functor::FunctorSurrogate, monad::MonadSurrogate

Example - Iterators

In the following example, iter map and filter are all conceptually “an iterator over usize

use std::iter::{Filter, Map};

let vec: Vec<usize> = vec![1, 2, 3, 4, 5];
let iter: std::vec::IntoIter<usize> = vec.into_iter();
let map: Map<std::vec::IntoIter<usize>, _> = iter.map(|n| n + 1);
let filter: Filter<Map<std::vec::IntoIter<usize>, _>, _> = map.filter(|n| n % 2 == 0);

this would imply:

<std::vec::IntoIter<usize> as Equiv>::To == std::vec::IntoIter<usize>
<Map<std::vec::IntoIter<usize>, _> as Equiv>::To == std::vec::IntoIter<usize>
<Filter<Map<std::vec::IntoIter<usize>, _>, _> as Equiv>::To == std::vec::IntoIter<usize>

Other examples:

  • Result<A, Infallible> is Equiv::To Result<A, !> (and vice versa)
  • IO<Lazy> is Equiv::To IO<Lazy::T> (IO<Suspend<_, usize>> == IO<usize>)

Required Associated Types§

source

type To

The target that Self is conceptually equivalent to

Implementors§

source§

impl<A> Equiv for IO<A>

§

type To = IO<A>

source§

impl<A, B, AB, IOA, IOAB> Equiv for Apply<A, B, AB, IOA, IOAB>

§

type To = IO<B>

source§

impl<F> Equiv for Suspend<F>where F: F1Once<()>,

§

type To = IO<<F as F1Once<()>>::Ret>

source§

impl<F, A, B, IOA> Equiv for Bind<F, A, B, IOA>where F: F1Once<A>, F::Ret: Equiv<To = IO<B>>, IOA: Equiv<To = IO<A>>,

§

type To = IO<B>

source§

impl<F, X, A, IOX> Equiv for Map<F, X, A, IOX>where F: F1Once<X>, IOX: Equiv<To = IO<X>>,

§

type To = IO<<F as F1Once<X>>::Ret>