rename classes to instances
This commit is contained in:
parent
032c4ea9b3
commit
d9c8cff1db
@ -1 +1 @@
|
|||||||
Subproject commit 80aa72c60ecd0ac605041d22df2ea6a66178c5be
|
Subproject commit f1dd33d61f7d1ce9c1d428ff0d75fb3efb2bb340
|
@ -55,13 +55,15 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A: 'a + Display> Display for UnbalancedReference<'a, classes::solo::SoloClass, A> {
|
impl<'a, A: 'a + Display> Display for UnbalancedReference<'a, instances::solo::SoloInstance, A> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_fmt(format_args!("{}", self.0()))
|
f.write_fmt(format_args!("{}", self.0()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, A: 'a + Display> Display for UnbalancedReference<'a, classes::result::ResultClass<()>, A> {
|
impl<'a, A: 'a + Display> Display
|
||||||
|
for UnbalancedReference<'a, instances::result::ResultInstance<()>, A>
|
||||||
|
{
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self.0() {
|
match self.0() {
|
||||||
Ok(node) => f.write_fmt(format_args!("{}", node)),
|
Ok(node) => f.write_fmt(format_args!("{}", node)),
|
||||||
@ -179,7 +181,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple_slices() {
|
fn test_simple_slices() {
|
||||||
let ctr: Rc<UnbalancedConstructor<classes::result::ResultClass<()>, _>> =
|
let ctr: Rc<UnbalancedConstructor<instances::result::ResultInstance<()>, _>> =
|
||||||
UnbalancedConstructor::rc(Box::new(|node| Box::new(move || Ok(node.clone()))));
|
UnbalancedConstructor::rc(Box::new(|node| Box::new(move || Ok(node.clone()))));
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let t_set = ctr.from_slice(&mut rng, &[0]);
|
let t_set = ctr.from_slice(&mut rng, &[0]);
|
||||||
@ -212,7 +214,7 @@ mod tests {
|
|||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_random_slices() {
|
fn test_random_slices() {
|
||||||
let ctr: Rc<UnbalancedConstructor<classes::result::ResultClass<()>, _>> =
|
let ctr: Rc<UnbalancedConstructor<instances::result::ResultInstance<()>, _>> =
|
||||||
UnbalancedConstructor::rc(Box::new(|node| Box::new(move || Ok(node.clone()))));
|
UnbalancedConstructor::rc(Box::new(|node| Box::new(move || Ok(node.clone()))));
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
@ -254,8 +256,10 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type TracedMonad =
|
type TracedMonad = instances::composition::CompositionInstance<
|
||||||
classes::composition::CompositionClass<TracedClass, classes::result::ResultClass<()>>;
|
TracedInstance,
|
||||||
|
instances::result::ResultInstance<()>,
|
||||||
|
>;
|
||||||
|
|
||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
|
22
src/func.rs
22
src/func.rs
@ -8,11 +8,11 @@
|
|||||||
//! * <https://hackage.haskell.org/package/base-4.18.0.0/docs/Control-Monad.html>
|
//! * <https://hackage.haskell.org/package/base-4.18.0.0/docs/Control-Monad.html>
|
||||||
|
|
||||||
mod applicative_select;
|
mod applicative_select;
|
||||||
pub mod classes;
|
|
||||||
pub mod clone_func;
|
pub mod clone_func;
|
||||||
mod controlflow;
|
mod controlflow;
|
||||||
pub mod copy_func;
|
pub mod copy_func;
|
||||||
pub mod derivations;
|
pub mod derivations;
|
||||||
|
pub mod instances;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod test_suite;
|
pub mod test_suite;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -23,8 +23,10 @@ pub use std::ops::ControlFlow;
|
|||||||
pub use radn_derive::{CovariantFunctor, SharedFunctor};
|
pub use radn_derive::{CovariantFunctor, SharedFunctor};
|
||||||
|
|
||||||
pub use self::applicative_select::{ApplicativeSelect, Selected};
|
pub use self::applicative_select::{ApplicativeSelect, Selected};
|
||||||
use self::controlflow::{BindableMut, ControlFlowClass};
|
use self::controlflow::{BindableMut, ControlFlowInstance};
|
||||||
pub use self::controlflow::{Iterative, IterativeWrapped};
|
pub use self::controlflow::{Iterative, IterativeWrapped};
|
||||||
|
#[cfg(doc)]
|
||||||
|
use self::instances::stackless::StacklessInstance;
|
||||||
|
|
||||||
/// Part of Haskell's `Functor f` responsible for having `f a`.
|
/// Part of Haskell's `Functor f` responsible for having `f a`.
|
||||||
///
|
///
|
||||||
@ -42,13 +44,13 @@ pub trait WeakFunctor {
|
|||||||
/// ```compile_fail
|
/// ```compile_fail
|
||||||
/// use radn_rs::func::*;
|
/// use radn_rs::func::*;
|
||||||
///
|
///
|
||||||
/// struct VecClass;
|
/// struct VecInstance;
|
||||||
///
|
///
|
||||||
/// impl WeakFunctor for VecClass {
|
/// impl WeakFunctor for VecInstance {
|
||||||
/// type F<'a, A> = Vec<A>;
|
/// type F<'a, A> = Vec<A>;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl Functor for VecClass {
|
/// impl Functor for VecInstance {
|
||||||
/// fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
/// fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
||||||
/// fa.into_iter().map(f).collect()
|
/// fa.into_iter().map(f).collect()
|
||||||
/// }
|
/// }
|
||||||
@ -61,13 +63,13 @@ pub trait WeakFunctor {
|
|||||||
/// ```
|
/// ```
|
||||||
/// use radn_rs::func::clone_func::*;
|
/// use radn_rs::func::clone_func::*;
|
||||||
///
|
///
|
||||||
/// struct VecClass;
|
/// struct VecInstance;
|
||||||
///
|
///
|
||||||
/// impl CloneWeakFunctor for VecClass {
|
/// impl CloneWeakFunctor for VecInstance {
|
||||||
/// type ClF<'a, A: Clone> = Vec<A>;
|
/// type ClF<'a, A: Clone> = Vec<A>;
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl CloneFunctor for VecClass {
|
/// impl CloneFunctor for VecInstance {
|
||||||
/// fn clone_fmap<'a, A: 'a + Clone, B: 'a + Clone>(
|
/// fn clone_fmap<'a, A: 'a + Clone, B: 'a + Clone>(
|
||||||
/// f: impl 'a + Fn(A) -> B,
|
/// f: impl 'a + Fn(A) -> B,
|
||||||
/// fa: Self::ClF<'a, A>,
|
/// fa: Self::ClF<'a, A>,
|
||||||
@ -182,7 +184,7 @@ pub trait Monad: Applicative {
|
|||||||
|
|
||||||
/// Included for optimisation and clarity.
|
/// Included for optimisation and clarity.
|
||||||
/// Generally, [`Monad::bind`] should be enough implement it.
|
/// Generally, [`Monad::bind`] should be enough implement it.
|
||||||
/// See [`classes::stackless::StacklessClass::iterate`] for a generic, though less-than ideal, blanket implementation.
|
/// See [`StacklessInstance::iterate`] for a generic, though less-than ideal, blanket implementation.
|
||||||
/// On practice, you generally shouldn't be using [`Monad::bind`]/[`Pure::pure`]/[`Functor::fmap`] here.
|
/// On practice, you generally shouldn't be using [`Monad::bind`]/[`Pure::pure`]/[`Functor::fmap`] here.
|
||||||
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
|
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
@ -256,7 +258,7 @@ pub trait LocalFunctor: WeakFunctor {
|
|||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
Self::stuff::<_, ControlFlowClass<A>>(state)
|
Self::stuff::<_, ControlFlowInstance<A>>(state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stuff wrapped result into another functor.
|
/// Stuff wrapped result into another functor.
|
||||||
|
@ -2,15 +2,15 @@ use std::marker::PhantomData;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub struct ControlFlowClass<C>(ControlFlow<(), C>);
|
pub struct ControlFlowInstance<C>(ControlFlow<(), C>);
|
||||||
|
|
||||||
impl<C> WeakFunctor for ControlFlowClass<C> {
|
impl<C> WeakFunctor for ControlFlowInstance<C> {
|
||||||
type F<'a, A: 'a> = ControlFlow<A, C>
|
type F<'a, A: 'a> = ControlFlow<A, C>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> Functor for ControlFlowClass<C> {
|
impl<C> Functor for ControlFlowInstance<C> {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -22,7 +22,7 @@ impl<C> Functor for ControlFlowClass<C> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C> Pure for ControlFlowClass<C> {
|
impl<C> Pure for ControlFlowInstance<C> {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
//! Implementation of some basic classes (in Haskell's meaning of a class).
|
//! Implementation of some basic instances (in Haskell's meaning of a instances).
|
||||||
//!
|
//!
|
||||||
//! To get an understanding of what classes are about, see [`option`].
|
//! To get an understanding of what instances are about, see [`option`].
|
||||||
//!
|
//!
|
||||||
//! For [`MonadFail<E>`] examples, see [`result`][^research].
|
//! For [`MonadFail<E>`] examples, see [`result`][^research].
|
||||||
//!
|
//!
|
||||||
@ -12,9 +12,9 @@
|
|||||||
//!
|
//!
|
||||||
//! For combining monads, see [`composition`][^research].
|
//! For combining monads, see [`composition`][^research].
|
||||||
//!
|
//!
|
||||||
//! [^production]: classes expected to be used in production.
|
//! [^production]: instances expected to be used in production.
|
||||||
//!
|
//!
|
||||||
//! [^research]: classes used for research purposes to enhance the abstract interfaces.
|
//! [^research]: instances used for research purposes to enhance the abstract interfaces.
|
||||||
|
|
||||||
#[cfg(doc)]
|
#[cfg(doc)]
|
||||||
use crate::func::*;
|
use crate::func::*;
|
@ -1,12 +1,12 @@
|
|||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
pub struct CompositionClass<U, V>(U, V);
|
pub struct CompositionInstance<U, V>(U, V);
|
||||||
|
|
||||||
impl<U: WeakFunctor, V: WeakFunctor> WeakFunctor for CompositionClass<U, V> {
|
impl<U: WeakFunctor, V: WeakFunctor> WeakFunctor for CompositionInstance<U, V> {
|
||||||
type F<'a, A: 'a> = U::F<'a, V::F<'a, A>> where Self: 'a;
|
type F<'a, A: 'a> = U::F<'a, V::F<'a, A>> where Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: Functor, V: Functor> Functor for CompositionClass<U, V> {
|
impl<U: Functor, V: Functor> Functor for CompositionInstance<U, V> {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -29,7 +29,7 @@ impl<U: Functor, V: Functor> Functor for CompositionClass<U, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: Pure, V: Pure> Pure for CompositionClass<U, V> {
|
impl<U: Pure, V: Pure> Pure for CompositionInstance<U, V> {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -38,7 +38,7 @@ impl<U: Pure, V: Pure> Pure for CompositionClass<U, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: ApplicativeLA2, V: ApplicativeSeq> ApplicativeSeq for CompositionClass<U, V> {
|
impl<U: ApplicativeLA2, V: ApplicativeSeq> ApplicativeSeq for CompositionInstance<U, V> {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -50,7 +50,7 @@ impl<U: ApplicativeLA2, V: ApplicativeSeq> ApplicativeSeq for CompositionClass<U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: ApplicativeLA2, V: ApplicativeLA2> ApplicativeLA2 for CompositionClass<U, V> {
|
impl<U: ApplicativeLA2, V: ApplicativeLA2> ApplicativeLA2 for CompositionInstance<U, V> {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -63,7 +63,7 @@ impl<U: ApplicativeLA2, V: ApplicativeLA2> ApplicativeLA2 for CompositionClass<U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: ApplicativeTuple, V: ApplicativeTuple> ApplicativeTuple for CompositionClass<U, V> {
|
impl<U: ApplicativeTuple, V: ApplicativeTuple> ApplicativeTuple for CompositionInstance<U, V> {
|
||||||
fn tuple<'a, A: 'a, B: 'a>(fab: (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>(fab: (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -72,7 +72,7 @@ impl<U: ApplicativeTuple, V: ApplicativeTuple> ApplicativeTuple for CompositionC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: ApplicativeSelect, V: Functor> ApplicativeSelect for CompositionClass<U, V> {
|
impl<U: ApplicativeSelect, V: Functor> ApplicativeSelect for CompositionInstance<U, V> {
|
||||||
fn select<'a, A: 'a, B: 'a, C: 'a>(
|
fn select<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(Selected<'a, A, B, Self>) -> C,
|
f: impl 'a + FnOnce(Selected<'a, A, B, Self>) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -92,7 +92,7 @@ impl<U: ApplicativeSelect, V: Functor> ApplicativeSelect for CompositionClass<U,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: Applicative, V: Applicative> Applicative for CompositionClass<U, V> {
|
impl<U: Applicative, V: Applicative> Applicative for CompositionInstance<U, V> {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -108,7 +108,7 @@ impl<U: Applicative, V: Applicative> Applicative for CompositionClass<U, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: Monad, V: Monad + LocalFunctor> Monad for CompositionClass<U, V> {
|
impl<U: Monad, V: Monad + LocalFunctor> Monad for CompositionInstance<U, V> {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -141,7 +141,7 @@ impl<
|
|||||||
'a,
|
'a,
|
||||||
U: 'a + Monad,
|
U: 'a + Monad,
|
||||||
V: 'a + Monad + LocalFunctor,
|
V: 'a + Monad + LocalFunctor,
|
||||||
F: Iterative<'a, T = CompositionClass<U, V>>,
|
F: Iterative<'a, T = CompositionInstance<U, V>>,
|
||||||
> Iterative<'a> for ComposedIterative<F>
|
> Iterative<'a> for ComposedIterative<F>
|
||||||
{
|
{
|
||||||
type B = <V as WeakFunctor>::F<'a, F::B>;
|
type B = <V as WeakFunctor>::F<'a, F::B>;
|
||||||
@ -159,7 +159,7 @@ impl<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E, U: Monad, V: Fail<E> + LocalFunctor> Fail<E> for CompositionClass<U, V> {
|
impl<E, U: Monad, V: Fail<E> + LocalFunctor> Fail<E> for CompositionInstance<U, V> {
|
||||||
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -169,7 +169,7 @@ impl<E, U: Monad, V: Fail<E> + LocalFunctor> Fail<E> for CompositionClass<U, V>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: LocalFunctor + Functor, V: LocalFunctor> LocalFunctor for CompositionClass<U, V> {
|
impl<U: LocalFunctor + Functor, V: LocalFunctor> LocalFunctor for CompositionInstance<U, V> {
|
||||||
fn unstuff<'a, A: 'a, B: 'a>(
|
fn unstuff<'a, A: 'a, B: 'a>(
|
||||||
state: Self::F<'a, ControlFlow<B, A>>,
|
state: Self::F<'a, ControlFlow<B, A>>,
|
||||||
) -> ControlFlow<Self::F<'a, B>, A>
|
) -> ControlFlow<Self::F<'a, B>, A>
|
||||||
@ -187,7 +187,7 @@ impl<U: LocalFunctor + Functor, V: LocalFunctor> LocalFunctor for CompositionCla
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<U: SharedFunctor + Functor, V: SharedFunctor> SharedFunctor for CompositionClass<U, V> {
|
impl<U: SharedFunctor + Functor, V: SharedFunctor> SharedFunctor for CompositionInstance<U, V> {
|
||||||
type Shared<'a, A: 'a + Clone> = U::Shared<'a, V::Shared<'a, A>>
|
type Shared<'a, A: 'a + Clone> = U::Shared<'a, V::Shared<'a, A>>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
@ -208,7 +208,7 @@ impl<U: SharedFunctor + Functor, V: SharedFunctor> SharedFunctor for Composition
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<U: CovariantFunctor + Functor, V: CovariantFunctor> CovariantFunctor
|
impl<U: CovariantFunctor + Functor, V: CovariantFunctor> CovariantFunctor
|
||||||
for CompositionClass<U, V>
|
for CompositionInstance<U, V>
|
||||||
{
|
{
|
||||||
fn variate<'a: 'b, 'b, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'b, A>
|
fn variate<'a: 'b, 'b, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'b, A>
|
||||||
where
|
where
|
@ -24,15 +24,15 @@ impl<A, E: Effect> WithEffect<A, E> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SharedFunctor, CovariantFunctor)]
|
#[derive(SharedFunctor, CovariantFunctor)]
|
||||||
pub struct EffectClass<E>(E);
|
pub struct EffectInstance<E>(E);
|
||||||
|
|
||||||
impl<E> WeakFunctor for EffectClass<E> {
|
impl<E> WeakFunctor for EffectInstance<E> {
|
||||||
type F<'a, A: 'a> = WithEffect<A, E>
|
type F<'a, A: 'a> = WithEffect<A, E>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Functor for EffectClass<E> {
|
impl<E> Functor for EffectInstance<E> {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -55,7 +55,7 @@ impl<E> Functor for EffectClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Effect> Pure for EffectClass<E> {
|
impl<E: Effect> Pure for EffectInstance<E> {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -67,7 +67,7 @@ impl<E: Effect> Pure for EffectClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Effect> ApplicativeSeq for EffectClass<E> {
|
impl<E: Effect> ApplicativeSeq for EffectInstance<E> {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -82,7 +82,7 @@ impl<E: Effect> ApplicativeSeq for EffectClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Effect> ApplicativeLA2 for EffectClass<E> {
|
impl<E: Effect> ApplicativeLA2 for EffectInstance<E> {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -98,7 +98,7 @@ impl<E: Effect> ApplicativeLA2 for EffectClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Effect> ApplicativeTuple for EffectClass<E> {
|
impl<E: Effect> ApplicativeTuple for EffectInstance<E> {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -110,9 +110,9 @@ impl<E: Effect> ApplicativeTuple for EffectClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Effect> ApplicativeSelect for EffectClass<E> {}
|
impl<E: Effect> ApplicativeSelect for EffectInstance<E> {}
|
||||||
|
|
||||||
impl<E: Effect> Applicative for EffectClass<E> {
|
impl<E: Effect> Applicative for EffectInstance<E> {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -136,7 +136,7 @@ impl<E: Effect> Applicative for EffectClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Effect> Monad for EffectClass<E> {
|
impl<E: Effect> Monad for EffectInstance<E> {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -171,7 +171,7 @@ impl<E: Effect> Monad for EffectClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> LocalFunctor for EffectClass<E> {
|
impl<E> LocalFunctor for EffectInstance<E> {
|
||||||
fn stuff<'a, A: 'a, T: 'a + Pure>(fa: Self::F<'a, T::F<'a, A>>) -> T::F<'a, Self::F<'a, A>>
|
fn stuff<'a, A: 'a, T: 'a + Pure>(fa: Self::F<'a, T::F<'a, A>>) -> T::F<'a, Self::F<'a, A>>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
@ -13,13 +13,13 @@ use futures::{
|
|||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
#[derive(CovariantFunctor)]
|
#[derive(CovariantFunctor)]
|
||||||
pub struct FutureClass;
|
pub struct FutureInstance;
|
||||||
|
|
||||||
impl WeakFunctor for FutureClass {
|
impl WeakFunctor for FutureInstance {
|
||||||
type F<'a, A: 'a> = Pin<Box<dyn 'a + Future<Output = A>>>;
|
type F<'a, A: 'a> = Pin<Box<dyn 'a + Future<Output = A>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Functor for FutureClass {
|
impl Functor for FutureInstance {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
||||||
Box::pin(async { f(fa.await) })
|
Box::pin(async { f(fa.await) })
|
||||||
}
|
}
|
||||||
@ -32,13 +32,13 @@ impl Functor for FutureClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pure for FutureClass {
|
impl Pure for FutureInstance {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
||||||
Box::pin(async { a })
|
Box::pin(async { a })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSeq for FutureClass {
|
impl ApplicativeSeq for FutureInstance {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -50,7 +50,7 @@ impl ApplicativeSeq for FutureClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeLA2 for FutureClass {
|
impl ApplicativeLA2 for FutureInstance {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -63,7 +63,7 @@ impl ApplicativeLA2 for FutureClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeTuple for FutureClass {
|
impl ApplicativeTuple for FutureInstance {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -72,7 +72,7 @@ impl ApplicativeTuple for FutureClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSelect for FutureClass {
|
impl ApplicativeSelect for FutureInstance {
|
||||||
fn select<'a, A: 'a, B: 'a, C: 'a>(
|
fn select<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(Selected<'a, A, B, Self>) -> C,
|
f: impl 'a + FnOnce(Selected<'a, A, B, Self>) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -90,7 +90,7 @@ impl ApplicativeSelect for FutureClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Applicative for FutureClass {
|
impl Applicative for FutureInstance {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
||||||
Box::pin(async { join!(fa, fb).1 })
|
Box::pin(async { join!(fa, fb).1 })
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ impl Applicative for FutureClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Monad for FutureClass {
|
impl Monad for FutureInstance {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -127,7 +127,7 @@ impl Monad for FutureClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SharedFunctor for FutureClass {
|
impl SharedFunctor for FutureInstance {
|
||||||
type Shared<'a, A: 'a + Clone> = Shared<Pin<Box<dyn 'a + Future<Output = A>>>>
|
type Shared<'a, A: 'a + Clone> = Shared<Pin<Box<dyn 'a + Future<Output = A>>>>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
@ -2,7 +2,7 @@
|
|||||||
//! Wrapped value is just a box pointing to the constructor function.
|
//! Wrapped value is just a box pointing to the constructor function.
|
||||||
//!
|
//!
|
||||||
//! Due to semantical laziness,
|
//! Due to semantical laziness,
|
||||||
//! [`LazyClass::replace`] and [`LazyClass::discard_first`]/[`LazyClass::discard_second`]
|
//! [`LazyInstance::replace`] and [`LazyInstance::discard_first`]/[`LazyInstance::discard_second`]
|
||||||
//! actually fully cancel the "unnecessary" computation.
|
//! actually fully cancel the "unnecessary" computation.
|
||||||
//!
|
//!
|
||||||
//! For stackless execution see [`super::stackless`].
|
//! For stackless execution see [`super::stackless`].
|
||||||
@ -12,13 +12,13 @@ use std::{cell::RefCell, rc::Rc};
|
|||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
#[derive(CovariantFunctor)]
|
#[derive(CovariantFunctor)]
|
||||||
pub struct LazyClass;
|
pub struct LazyInstance;
|
||||||
|
|
||||||
impl WeakFunctor for LazyClass {
|
impl WeakFunctor for LazyInstance {
|
||||||
type F<'a, A: 'a> = Box<dyn 'a + FnOnce() -> A>;
|
type F<'a, A: 'a> = Box<dyn 'a + FnOnce() -> A>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Functor for LazyClass {
|
impl Functor for LazyInstance {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
||||||
Box::new(|| f(fa()))
|
Box::new(|| f(fa()))
|
||||||
}
|
}
|
||||||
@ -34,13 +34,13 @@ impl Functor for LazyClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pure for LazyClass {
|
impl Pure for LazyInstance {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
||||||
Box::new(|| a)
|
Box::new(|| a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSeq for LazyClass {
|
impl ApplicativeSeq for LazyInstance {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -49,7 +49,7 @@ impl ApplicativeSeq for LazyClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeLA2 for LazyClass {
|
impl ApplicativeLA2 for LazyInstance {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -59,7 +59,7 @@ impl ApplicativeLA2 for LazyClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeTuple for LazyClass {
|
impl ApplicativeTuple for LazyInstance {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -68,9 +68,9 @@ impl ApplicativeTuple for LazyClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSelect for LazyClass {}
|
impl ApplicativeSelect for LazyInstance {}
|
||||||
|
|
||||||
impl Applicative for LazyClass {
|
impl Applicative for LazyInstance {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
||||||
drop(fa);
|
drop(fa);
|
||||||
fb
|
fb
|
||||||
@ -82,7 +82,7 @@ impl Applicative for LazyClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Monad for LazyClass {
|
impl Monad for LazyInstance {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -116,7 +116,7 @@ fn unshare<'a, A: 'a + Clone>(shared: &mut Option<Box<dyn 'a + FnOnce() -> A>>)
|
|||||||
a
|
a
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SharedFunctor for LazyClass {
|
impl SharedFunctor for LazyInstance {
|
||||||
type Shared<'a, A: 'a + Clone> = Rc<RefCell<Option<Box<dyn 'a + FnOnce() -> A>>>>
|
type Shared<'a, A: 'a + Clone> = Rc<RefCell<Option<Box<dyn 'a + FnOnce() -> A>>>>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
@ -2,7 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! If any of the input values are [`None`], you can expect the output to be [`None`] as well.
|
//! If any of the input values are [`None`], you can expect the output to be [`None`] as well.
|
||||||
//! That includes
|
//! That includes
|
||||||
//! [`OptionClass::replace`] and [`OptionClass::discard_first`]/[`OptionClass::discard_second`],
|
//! [`OptionInstance::replace`] and [`OptionInstance::discard_first`]/[`OptionInstance::discard_second`],
|
||||||
//! even if the value of the option would be ignored.
|
//! even if the value of the option would be ignored.
|
||||||
//!
|
//!
|
||||||
//! For [`Result<A, E>`] alternative see [`super::result`]
|
//! For [`Result<A, E>`] alternative see [`super::result`]
|
||||||
@ -10,13 +10,13 @@
|
|||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
#[derive(SharedFunctor, CovariantFunctor)]
|
#[derive(SharedFunctor, CovariantFunctor)]
|
||||||
pub struct OptionClass;
|
pub struct OptionInstance;
|
||||||
|
|
||||||
impl WeakFunctor for OptionClass {
|
impl WeakFunctor for OptionInstance {
|
||||||
type F<'a, A: 'a> = Option<A>;
|
type F<'a, A: 'a> = Option<A>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Functor for OptionClass {
|
impl Functor for OptionInstance {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
||||||
fa.map(f)
|
fa.map(f)
|
||||||
}
|
}
|
||||||
@ -38,13 +38,13 @@ impl Functor for OptionClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pure for OptionClass {
|
impl Pure for OptionInstance {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
||||||
Some(a)
|
Some(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSeq for OptionClass {
|
impl ApplicativeSeq for OptionInstance {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -53,7 +53,7 @@ impl ApplicativeSeq for OptionClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeLA2 for OptionClass {
|
impl ApplicativeLA2 for OptionInstance {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -63,7 +63,7 @@ impl ApplicativeLA2 for OptionClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeTuple for OptionClass {
|
impl ApplicativeTuple for OptionInstance {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -72,9 +72,9 @@ impl ApplicativeTuple for OptionClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSelect for OptionClass {}
|
impl ApplicativeSelect for OptionInstance {}
|
||||||
|
|
||||||
impl Applicative for OptionClass {
|
impl Applicative for OptionInstance {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
||||||
fa?;
|
fa?;
|
||||||
fb
|
fb
|
||||||
@ -86,7 +86,7 @@ impl Applicative for OptionClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Monad for OptionClass {
|
impl Monad for OptionInstance {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -111,7 +111,7 @@ impl Monad for OptionClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LocalFunctor for OptionClass {
|
impl LocalFunctor for OptionInstance {
|
||||||
fn unstuff<'a, A: 'a, B: 'a>(
|
fn unstuff<'a, A: 'a, B: 'a>(
|
||||||
state: Self::F<'a, ControlFlow<B, A>>,
|
state: Self::F<'a, ControlFlow<B, A>>,
|
||||||
) -> ControlFlow<Self::F<'a, B>, A>
|
) -> ControlFlow<Self::F<'a, B>, A>
|
||||||
@ -136,7 +136,7 @@ impl LocalFunctor for OptionClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fail<()> for OptionClass {
|
impl Fail<()> for OptionInstance {
|
||||||
fn fail<'a, A: 'a>(_e: ()) -> Self::F<'a, A>
|
fn fail<'a, A: 'a>(_e: ()) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -149,7 +149,7 @@ impl Fail<()> for OptionClass {
|
|||||||
mod option_tests {
|
mod option_tests {
|
||||||
use super::{test_suite, tests, Functor};
|
use super::{test_suite, tests, Functor};
|
||||||
|
|
||||||
use super::OptionClass as T;
|
use super::OptionInstance as T;
|
||||||
|
|
||||||
impl tests::Eqr for T {
|
impl tests::Eqr for T {
|
||||||
fn eqr<'a, A: PartialEq + std::fmt::Debug + 'a>(
|
fn eqr<'a, A: PartialEq + std::fmt::Debug + 'a>(
|
@ -2,7 +2,7 @@ use std::marker::PhantomData;
|
|||||||
|
|
||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
pub struct OverloadClass<T, O>(T, O);
|
pub struct OverloadInstance<T, O>(T, O);
|
||||||
|
|
||||||
pub trait DeriveWeakFunctor {}
|
pub trait DeriveWeakFunctor {}
|
||||||
impl<O: DeriveFunctor> DeriveWeakFunctor for O {}
|
impl<O: DeriveFunctor> DeriveWeakFunctor for O {}
|
||||||
@ -12,13 +12,13 @@ pub trait DeriveApplicative {}
|
|||||||
impl<O: DeriveMonad> DeriveApplicative for O {}
|
impl<O: DeriveMonad> DeriveApplicative for O {}
|
||||||
pub trait DeriveMonad {}
|
pub trait DeriveMonad {}
|
||||||
|
|
||||||
impl<T: WeakFunctor, O: DeriveWeakFunctor> WeakFunctor for OverloadClass<T, O> {
|
impl<T: WeakFunctor, O: DeriveWeakFunctor> WeakFunctor for OverloadInstance<T, O> {
|
||||||
type F<'a, A: 'a> = T::F<'a, A>
|
type F<'a, A: 'a> = T::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Functor, O: DeriveFunctor> Functor for OverloadClass<T, O> {
|
impl<T: Functor, O: DeriveFunctor> Functor for OverloadInstance<T, O> {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -41,7 +41,7 @@ impl<T: Functor, O: DeriveFunctor> Functor for OverloadClass<T, O> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Pure, O: DeriveApplicative> Pure for OverloadClass<T, O> {
|
impl<T: Pure, O: DeriveApplicative> Pure for OverloadInstance<T, O> {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -50,7 +50,7 @@ impl<T: Pure, O: DeriveApplicative> Pure for OverloadClass<T, O> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ApplicativeSeq, O: DeriveApplicative> ApplicativeSeq for OverloadClass<T, O> {
|
impl<T: ApplicativeSeq, O: DeriveApplicative> ApplicativeSeq for OverloadInstance<T, O> {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -62,7 +62,7 @@ impl<T: ApplicativeSeq, O: DeriveApplicative> ApplicativeSeq for OverloadClass<T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ApplicativeLA2, O: DeriveApplicative> ApplicativeLA2 for OverloadClass<T, O> {
|
impl<T: ApplicativeLA2, O: DeriveApplicative> ApplicativeLA2 for OverloadInstance<T, O> {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -75,7 +75,7 @@ impl<T: ApplicativeLA2, O: DeriveApplicative> ApplicativeLA2 for OverloadClass<T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ApplicativeTuple, O: DeriveApplicative> ApplicativeTuple for OverloadClass<T, O> {
|
impl<T: ApplicativeTuple, O: DeriveApplicative> ApplicativeTuple for OverloadInstance<T, O> {
|
||||||
fn tuple<'a, A: 'a, B: 'a>(fab: (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>(fab: (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -84,9 +84,9 @@ impl<T: ApplicativeTuple, O: DeriveApplicative> ApplicativeTuple for OverloadCla
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ApplicativeTuple, O: DeriveApplicative> ApplicativeSelect for OverloadClass<T, O> {}
|
impl<T: ApplicativeTuple, O: DeriveApplicative> ApplicativeSelect for OverloadInstance<T, O> {}
|
||||||
|
|
||||||
impl<T: Applicative, O: DeriveApplicative> Applicative for OverloadClass<T, O> {
|
impl<T: Applicative, O: DeriveApplicative> Applicative for OverloadInstance<T, O> {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -110,7 +110,7 @@ impl<F, O> OverloadIterative<F, O> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: 'a + Monad, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadClass<T, O>>>
|
impl<'a, T: 'a + Monad, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadInstance<T, O>>>
|
||||||
Iterative<'a> for OverloadIterative<F, O>
|
Iterative<'a> for OverloadIterative<F, O>
|
||||||
{
|
{
|
||||||
type B = F::B;
|
type B = F::B;
|
||||||
@ -128,7 +128,7 @@ impl<'a, T: 'a + Monad, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadClass<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Monad, O: DeriveMonad> Monad for OverloadClass<T, O> {
|
impl<T: Monad, O: DeriveMonad> Monad for OverloadInstance<T, O> {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -159,7 +159,7 @@ pub struct DeriveFail<Ex>(Ex);
|
|||||||
|
|
||||||
impl<Ex> DeriveMonad for DeriveFail<Ex> {}
|
impl<Ex> DeriveMonad for DeriveFail<Ex> {}
|
||||||
|
|
||||||
impl<E, Ex, T: MonadFail<Result<E, Ex>>> Fail<E> for OverloadClass<T, DeriveFail<Ex>> {
|
impl<E, Ex, T: MonadFail<Result<E, Ex>>> Fail<E> for OverloadInstance<T, DeriveFail<Ex>> {
|
||||||
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -172,7 +172,7 @@ impl<E, Ex, T: MonadFail<Result<E, Ex>>> Fail<E> for OverloadClass<T, DeriveFail
|
|||||||
struct DeriveFailAny<Ex, Fallible>(Ex, Fallible);
|
struct DeriveFailAny<Ex, Fallible>(Ex, Fallible);
|
||||||
|
|
||||||
impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
||||||
type W<E> = OverloadClass<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>;
|
type W<E> = OverloadInstance<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>;
|
||||||
|
|
||||||
type T = Fallible::W<Ex>;
|
type T = Fallible::W<Ex>;
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: SharedFunctor, O: DeriveWeakFunctor> SharedFunctor for OverloadClass<T, O> {
|
impl<T: SharedFunctor, O: DeriveWeakFunctor> SharedFunctor for OverloadInstance<T, O> {
|
||||||
type Shared<'a, A: 'a + Clone> = T::Shared<'a, A>
|
type Shared<'a, A: 'a + Clone> = T::Shared<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
@ -260,7 +260,7 @@ impl<T: SharedFunctor, O: DeriveWeakFunctor> SharedFunctor for OverloadClass<T,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: CovariantFunctor, O: DeriveWeakFunctor> CovariantFunctor for OverloadClass<T, O> {
|
impl<T: CovariantFunctor, O: DeriveWeakFunctor> CovariantFunctor for OverloadInstance<T, O> {
|
||||||
fn variate<'a: 'b, 'b, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'b, A>
|
fn variate<'a: 'b, 'b, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'b, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -269,4 +269,4 @@ impl<T: CovariantFunctor, O: DeriveWeakFunctor> CovariantFunctor for OverloadCla
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type EmbedFail<T, Ex> = OverloadClass<T, DeriveFail<Ex>>;
|
pub type EmbedFail<T, Ex> = OverloadInstance<T, DeriveFail<Ex>>;
|
@ -2,7 +2,7 @@
|
|||||||
//!
|
//!
|
||||||
//! If any of the input values are [`Err`], you can expect the output to be [`Err`] as well.
|
//! If any of the input values are [`Err`], you can expect the output to be [`Err`] as well.
|
||||||
//! That includes
|
//! That includes
|
||||||
//! [`ResultClass::replace`] and [`ResultClass::discard_first`]/[`ResultClass::discard_second`],
|
//! [`ResultInstance::replace`] and [`ResultInstance::discard_first`]/[`ResultInstance::discard_second`],
|
||||||
//! even if the value of the option would be ignored.
|
//! even if the value of the option would be ignored.
|
||||||
//!
|
//!
|
||||||
//! For [`Option<A>`] alternative see [`super::option`]
|
//! For [`Option<A>`] alternative see [`super::option`]
|
||||||
@ -10,13 +10,13 @@
|
|||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
#[derive(SharedFunctor, CovariantFunctor)]
|
#[derive(SharedFunctor, CovariantFunctor)]
|
||||||
pub struct ResultClass<E>(E);
|
pub struct ResultInstance<E>(E);
|
||||||
|
|
||||||
impl<E> WeakFunctor for ResultClass<E> {
|
impl<E> WeakFunctor for ResultInstance<E> {
|
||||||
type F<'a, A: 'a> = Result<A, E> where Self: 'a;
|
type F<'a, A: 'a> = Result<A, E> where Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Functor for ResultClass<E> {
|
impl<E> Functor for ResultInstance<E> {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -41,7 +41,7 @@ impl<E> Functor for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Pure for ResultClass<E> {
|
impl<E> Pure for ResultInstance<E> {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -50,7 +50,7 @@ impl<E> Pure for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeSeq for ResultClass<E> {
|
impl<E> ApplicativeSeq for ResultInstance<E> {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -62,7 +62,7 @@ impl<E> ApplicativeSeq for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeLA2 for ResultClass<E> {
|
impl<E> ApplicativeLA2 for ResultInstance<E> {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -75,7 +75,7 @@ impl<E> ApplicativeLA2 for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeTuple for ResultClass<E> {
|
impl<E> ApplicativeTuple for ResultInstance<E> {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -84,9 +84,9 @@ impl<E> ApplicativeTuple for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeSelect for ResultClass<E> {}
|
impl<E> ApplicativeSelect for ResultInstance<E> {}
|
||||||
|
|
||||||
impl<E> Applicative for ResultClass<E> {
|
impl<E> Applicative for ResultInstance<E> {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -104,7 +104,7 @@ impl<E> Applicative for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Monad for ResultClass<E> {
|
impl<E> Monad for ResultInstance<E> {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -135,7 +135,7 @@ impl<E> Monad for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> LocalFunctor for ResultClass<E> {
|
impl<E> LocalFunctor for ResultInstance<E> {
|
||||||
fn unstuff<'a, A: 'a, B: 'a>(
|
fn unstuff<'a, A: 'a, B: 'a>(
|
||||||
state: Self::F<'a, ControlFlow<B, A>>,
|
state: Self::F<'a, ControlFlow<B, A>>,
|
||||||
) -> ControlFlow<Self::F<'a, B>, A>
|
) -> ControlFlow<Self::F<'a, B>, A>
|
||||||
@ -160,7 +160,7 @@ impl<E> LocalFunctor for ResultClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Fail<E> for ResultClass<E> {
|
impl<E> Fail<E> for ResultInstance<E> {
|
||||||
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -185,9 +185,9 @@ impl<'a, A: 'a, E0: 'a> ResultExt<'a, A, E0> for Result<A, E0> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl MonadFailAny for ResultFailAny {
|
impl MonadFailAny for ResultFailAny {
|
||||||
type W<E> = ResultClass<E>;
|
type W<E> = ResultInstance<E>;
|
||||||
|
|
||||||
type T = classes::solo::SoloClass;
|
type T = instances::solo::SoloInstance;
|
||||||
|
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
||||||
@ -254,7 +254,7 @@ impl MonadFailAny for ResultFailAny {
|
|||||||
pub struct ResultFailOver<T: Monad>(T);
|
pub struct ResultFailOver<T: Monad>(T);
|
||||||
|
|
||||||
impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
||||||
type W<E> = super::composition::CompositionClass<T, ResultClass<E>>;
|
type W<E> = super::composition::CompositionInstance<T, ResultInstance<E>>;
|
||||||
|
|
||||||
type T = T;
|
type T = T;
|
||||||
|
|
@ -5,13 +5,13 @@
|
|||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
#[derive(SharedFunctor, CovariantFunctor)]
|
#[derive(SharedFunctor, CovariantFunctor)]
|
||||||
pub struct SoloClass;
|
pub struct SoloInstance;
|
||||||
|
|
||||||
impl WeakFunctor for SoloClass {
|
impl WeakFunctor for SoloInstance {
|
||||||
type F<'a, A: 'a> = A;
|
type F<'a, A: 'a> = A;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Functor for SoloClass {
|
impl Functor for SoloInstance {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B> {
|
||||||
f(fa)
|
f(fa)
|
||||||
}
|
}
|
||||||
@ -26,13 +26,13 @@ impl Functor for SoloClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pure for SoloClass {
|
impl Pure for SoloInstance {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
||||||
a
|
a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSeq for SoloClass {
|
impl ApplicativeSeq for SoloInstance {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -41,7 +41,7 @@ impl ApplicativeSeq for SoloClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeLA2 for SoloClass {
|
impl ApplicativeLA2 for SoloInstance {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -51,7 +51,7 @@ impl ApplicativeLA2 for SoloClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeTuple for SoloClass {
|
impl ApplicativeTuple for SoloInstance {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -60,9 +60,9 @@ impl ApplicativeTuple for SoloClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSelect for SoloClass {}
|
impl ApplicativeSelect for SoloInstance {}
|
||||||
|
|
||||||
impl Applicative for SoloClass {
|
impl Applicative for SoloInstance {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B> {
|
||||||
drop(fa);
|
drop(fa);
|
||||||
fb
|
fb
|
||||||
@ -74,7 +74,7 @@ impl Applicative for SoloClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Monad for SoloClass {
|
impl Monad for SoloInstance {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -99,7 +99,7 @@ impl Monad for SoloClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LocalFunctor for SoloClass {
|
impl LocalFunctor for SoloInstance {
|
||||||
fn unstuff<'a, A: 'a, B: 'a>(
|
fn unstuff<'a, A: 'a, B: 'a>(
|
||||||
state: Self::F<'a, ControlFlow<B, A>>,
|
state: Self::F<'a, ControlFlow<B, A>>,
|
||||||
) -> ControlFlow<Self::F<'a, B>, A>
|
) -> ControlFlow<Self::F<'a, B>, A>
|
||||||
@ -117,7 +117,7 @@ impl LocalFunctor for SoloClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fail<std::convert::Infallible> for SoloClass {
|
impl Fail<std::convert::Infallible> for SoloInstance {
|
||||||
fn fail<'a, A: 'a>(e: std::convert::Infallible) -> Self::F<'a, A>
|
fn fail<'a, A: 'a>(e: std::convert::Infallible) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
@ -117,13 +117,13 @@ impl<'a, A: 'a> From<A> for Stackless<'a, A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StacklessClass;
|
pub struct StacklessInstance;
|
||||||
|
|
||||||
impl WeakFunctor for StacklessClass {
|
impl WeakFunctor for StacklessInstance {
|
||||||
type F<'a, A: 'a> = Stackless<'a, A>;
|
type F<'a, A: 'a> = Stackless<'a, A>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Functor for StacklessClass {
|
impl Functor for StacklessInstance {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -147,13 +147,13 @@ impl Functor for StacklessClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pure for StacklessClass {
|
impl Pure for StacklessInstance {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A> {
|
||||||
Stackless::from(a)
|
Stackless::from(a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSeq for StacklessClass {
|
impl ApplicativeSeq for StacklessInstance {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -165,7 +165,7 @@ impl ApplicativeSeq for StacklessClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeLA2 for StacklessClass {
|
impl ApplicativeLA2 for StacklessInstance {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -178,7 +178,7 @@ impl ApplicativeLA2 for StacklessClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeTuple for StacklessClass {
|
impl ApplicativeTuple for StacklessInstance {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -187,9 +187,9 @@ impl ApplicativeTuple for StacklessClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplicativeSelect for StacklessClass {}
|
impl ApplicativeSelect for StacklessInstance {}
|
||||||
|
|
||||||
impl Applicative for StacklessClass {
|
impl Applicative for StacklessInstance {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -215,7 +215,7 @@ impl Applicative for StacklessClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Monad for StacklessClass {
|
impl Monad for StacklessInstance {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -263,7 +263,7 @@ impl Monad for StacklessClass {
|
|||||||
mod stackless_test {
|
mod stackless_test {
|
||||||
use super::{test_suite, tests, Stackless};
|
use super::{test_suite, tests, Stackless};
|
||||||
|
|
||||||
use super::StacklessClass as T;
|
use super::StacklessInstance as T;
|
||||||
|
|
||||||
impl tests::Eqr for T {
|
impl tests::Eqr for T {
|
||||||
fn eqr<'a, A: PartialEq + std::fmt::Debug + 'a>(
|
fn eqr<'a, A: PartialEq + std::fmt::Debug + 'a>(
|
@ -8,13 +8,13 @@ use futures::{
|
|||||||
use crate::func::*;
|
use crate::func::*;
|
||||||
|
|
||||||
#[derive(CovariantFunctor)]
|
#[derive(CovariantFunctor)]
|
||||||
pub struct TryFutureClass<E>(E);
|
pub struct TryFutureInstance<E>(E);
|
||||||
|
|
||||||
impl<E> WeakFunctor for TryFutureClass<E> {
|
impl<E> WeakFunctor for TryFutureInstance<E> {
|
||||||
type F<'a, A: 'a> = Pin<Box<dyn 'a + Future<Output = Result<A, E>>>> where Self: 'a;
|
type F<'a, A: 'a> = Pin<Box<dyn 'a + Future<Output = Result<A, E>>>> where Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Functor for TryFutureClass<E> {
|
impl<E> Functor for TryFutureInstance<E> {
|
||||||
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -33,7 +33,7 @@ impl<E> Functor for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Pure for TryFutureClass<E> {
|
impl<E> Pure for TryFutureInstance<E> {
|
||||||
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -42,7 +42,7 @@ impl<E> Pure for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeSeq for TryFutureClass<E> {
|
impl<E> ApplicativeSeq for TryFutureInstance<E> {
|
||||||
fn seq<'a, A: 'a, B: 'a>(
|
fn seq<'a, A: 'a, B: 'a>(
|
||||||
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
ff: Self::F<'a, impl 'a + FnOnce(A) -> B>,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -57,7 +57,7 @@ impl<E> ApplicativeSeq for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeLA2 for TryFutureClass<E> {
|
impl<E> ApplicativeLA2 for TryFutureInstance<E> {
|
||||||
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
fn la2<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(A, B) -> C,
|
f: impl 'a + FnOnce(A, B) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -73,7 +73,7 @@ impl<E> ApplicativeLA2 for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeTuple for TryFutureClass<E> {
|
impl<E> ApplicativeTuple for TryFutureInstance<E> {
|
||||||
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
fn tuple<'a, A: 'a, B: 'a>((fa, fb): (Self::F<'a, A>, Self::F<'a, B>)) -> Self::F<'a, (A, B)>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -82,7 +82,7 @@ impl<E> ApplicativeTuple for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> ApplicativeSelect for TryFutureClass<E> {
|
impl<E> ApplicativeSelect for TryFutureInstance<E> {
|
||||||
fn select<'a, A: 'a, B: 'a, C: 'a>(
|
fn select<'a, A: 'a, B: 'a, C: 'a>(
|
||||||
f: impl 'a + FnOnce(Selected<'a, A, B, Self>) -> C,
|
f: impl 'a + FnOnce(Selected<'a, A, B, Self>) -> C,
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
@ -102,7 +102,7 @@ impl<E> ApplicativeSelect for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Applicative for TryFutureClass<E> {
|
impl<E> Applicative for TryFutureInstance<E> {
|
||||||
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
fn discard_first<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, fb: Self::F<'a, B>) -> Self::F<'a, B>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -118,7 +118,7 @@ impl<E> Applicative for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Monad for TryFutureClass<E> {
|
impl<E> Monad for TryFutureInstance<E> {
|
||||||
fn bind<'a, A: 'a, B: 'a>(
|
fn bind<'a, A: 'a, B: 'a>(
|
||||||
fa: Self::F<'a, A>,
|
fa: Self::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
|
||||||
@ -151,7 +151,7 @@ impl<E> Monad for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Clone> SharedFunctor for TryFutureClass<E> {
|
impl<E: Clone> SharedFunctor for TryFutureInstance<E> {
|
||||||
type Shared<'a, A: 'a + Clone> = Shared<Pin<Box<dyn 'a + Future<Output = Result<A, E>>>>>
|
type Shared<'a, A: 'a + Clone> = Shared<Pin<Box<dyn 'a + Future<Output = Result<A, E>>>>>
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
@ -171,7 +171,7 @@ impl<E: Clone> SharedFunctor for TryFutureClass<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> Fail<E> for TryFutureClass<E> {
|
impl<E> Fail<E> for TryFutureInstance<E> {
|
||||||
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
@ -184,9 +184,9 @@ impl<E> Fail<E> for TryFutureClass<E> {
|
|||||||
pub struct FutureFailAny;
|
pub struct FutureFailAny;
|
||||||
|
|
||||||
impl MonadFailAny for FutureFailAny {
|
impl MonadFailAny for FutureFailAny {
|
||||||
type W<E> = TryFutureClass<E>;
|
type W<E> = TryFutureInstance<E>;
|
||||||
|
|
||||||
type T = classes::future::FutureClass;
|
type T = instances::future::FutureInstance;
|
||||||
|
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
@ -22,9 +22,9 @@ pub use self::traced::*;
|
|||||||
pub struct TracedDiagnostic;
|
pub struct TracedDiagnostic;
|
||||||
|
|
||||||
/// Implementation of [`Monad`] for [Traced] objects.
|
/// Implementation of [`Monad`] for [Traced] objects.
|
||||||
pub type TracedClass = classes::effect::EffectClass<TraceBox>;
|
pub type TracedInstance = instances::effect::EffectInstance<TraceBox>;
|
||||||
|
|
||||||
impl classes::effect::Effect for TraceBox {
|
impl instances::effect::Effect for TraceBox {
|
||||||
fn e_pure() -> Self {
|
fn e_pure() -> Self {
|
||||||
TraceBox::pure()
|
TraceBox::pure()
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ impl<A> Traced<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Diagnostic<TracedClass> for TracedDiagnostic {
|
impl Diagnostic<TracedInstance> for TracedDiagnostic {
|
||||||
fn after<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> {
|
fn after<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> {
|
||||||
fa.after(TraceBox::event(event()))
|
fa.after(TraceBox::event(event()))
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,15 @@ struct TracedResolver<'a, Ctx: 'a + Context> {
|
|||||||
resolver: Rc<dyn Resolver<'a, Ctx>>,
|
resolver: Rc<dyn Resolver<'a, Ctx>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context<T = TracedClass>> TracedResolver<'a, Ctx> {
|
impl<'a, Ctx: 'a + Context<T = TracedInstance>> TracedResolver<'a, Ctx> {
|
||||||
fn wrap(resolver: Rc<dyn Resolver<'a, Ctx>>) -> Rc<dyn Resolver<'a, Ctx>> {
|
fn wrap(resolver: Rc<dyn Resolver<'a, Ctx>>) -> Rc<dyn Resolver<'a, Ctx>> {
|
||||||
Rc::new(Self { resolver })
|
Rc::new(Self { resolver })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context<T = TracedClass>> Resolver<'a, Ctx> for TracedResolver<'a, Ctx> {
|
impl<'a, Ctx: 'a + Context<T = TracedInstance>> Resolver<'a, Ctx> for TracedResolver<'a, Ctx> {
|
||||||
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> {
|
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> {
|
||||||
TracedClass::fmap(
|
TracedInstance::fmap(
|
||||||
|resolved| {
|
|resolved| {
|
||||||
let (src, resolver) = resolved?;
|
let (src, resolver) = resolved?;
|
||||||
let delayed: Rc<dyn Resolver<'a, Ctx>> = Rc::new(TracedResolver { resolver });
|
let delayed: Rc<dyn Resolver<'a, Ctx>> = Rc::new(TracedResolver { resolver });
|
||||||
@ -27,7 +27,9 @@ impl<'a, Ctx: 'a + Context<T = TracedClass>> Resolver<'a, Ctx> for TracedResolve
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Extension trait to trace the evaluation flow.
|
/// Extension trait to trace the evaluation flow.
|
||||||
pub trait Traceable<'a, Ctx: 'a + Context<T = TracedClass>>: Mentionable<'a, Ctx> + Sized {
|
pub trait Traceable<'a, Ctx: 'a + Context<T = TracedInstance>>:
|
||||||
|
Mentionable<'a, Ctx> + Sized
|
||||||
|
{
|
||||||
/// Re-cast the value, adding an extra[^extra]
|
/// Re-cast the value, adding an extra[^extra]
|
||||||
/// note ([`RenderedCommon::Resolution`]) to the trace on each resolution.
|
/// note ([`RenderedCommon::Resolution`]) to the trace on each resolution.
|
||||||
///
|
///
|
||||||
@ -36,7 +38,7 @@ pub trait Traceable<'a, Ctx: 'a + Context<T = TracedClass>>: Mentionable<'a, Ctx
|
|||||||
fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self>;
|
fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context<T = TracedClass>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A
|
impl<'a, Ctx: 'a + Context<T = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A
|
||||||
where
|
where
|
||||||
Ctx::LookupError<'a>: From<CastError<'a>>,
|
Ctx::LookupError<'a>: From<CastError<'a>>,
|
||||||
{
|
{
|
||||||
|
@ -3,4 +3,4 @@ use super::*;
|
|||||||
/// Wrapper containing the value and the corresponding execution trace.
|
/// Wrapper containing the value and the corresponding execution trace.
|
||||||
///
|
///
|
||||||
/// For what the trace contains, see its rendered form, [`RenderedAny`].
|
/// For what the trace contains, see its rendered form, [`RenderedAny`].
|
||||||
pub type Traced<A> = classes::effect::WithEffect<A, TraceBox>;
|
pub type Traced<A> = instances::effect::WithEffect<A, TraceBox>;
|
||||||
|
@ -67,9 +67,9 @@ impl<'a> Display for TestLookupError<'a> {
|
|||||||
impl<'a> Error for TestLookupError<'a> {}
|
impl<'a> Error for TestLookupError<'a> {}
|
||||||
|
|
||||||
impl Context for TestContextPlain {
|
impl Context for TestContextPlain {
|
||||||
type T = classes::solo::SoloClass;
|
type T = instances::solo::SoloInstance;
|
||||||
|
|
||||||
type Fallible = classes::result::ResultFailAny;
|
type Fallible = instances::result::ResultFailAny;
|
||||||
|
|
||||||
type D = NoDiagnostic;
|
type D = NoDiagnostic;
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ use super::*;
|
|||||||
pub struct TestContextCounted;
|
pub struct TestContextCounted;
|
||||||
|
|
||||||
impl Context for TestContextCounted {
|
impl Context for TestContextCounted {
|
||||||
type T = CountedClass;
|
type T = CountedInstance;
|
||||||
|
|
||||||
type Fallible = classes::result::ResultFailOver<Self::T>;
|
type Fallible = instances::result::ResultFailOver<Self::T>;
|
||||||
|
|
||||||
type D = NoDiagnostic;
|
type D = NoDiagnostic;
|
||||||
|
|
||||||
@ -22,9 +22,9 @@ impl Context for TestContextCounted {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type CountedClass = classes::effect::EffectClass<usize>;
|
pub type CountedInstance = instances::effect::EffectInstance<usize>;
|
||||||
|
|
||||||
impl classes::effect::Effect for usize {
|
impl instances::effect::Effect for usize {
|
||||||
fn e_pure() -> Self {
|
fn e_pure() -> Self {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ impl classes::effect::Effect for usize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Counted<A> = classes::effect::WithEffect<A, usize>;
|
pub type Counted<A> = instances::effect::WithEffect<A, usize>;
|
||||||
|
|
||||||
impl<A> Counted<A> {
|
impl<A> Counted<A> {
|
||||||
fn add(self, n: usize) -> Self {
|
fn add(self, n: usize) -> Self {
|
||||||
@ -67,7 +67,7 @@ impl<'a> CountedResolver<'a> {
|
|||||||
|
|
||||||
impl<'a> Resolver<'a, TestContextCounted> for CountedResolver<'a> {
|
impl<'a> Resolver<'a, TestContextCounted> for CountedResolver<'a> {
|
||||||
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, TestContextCounted> {
|
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, TestContextCounted> {
|
||||||
CountedClass::fmap(
|
CountedInstance::fmap(
|
||||||
|resolved| {
|
|resolved| {
|
||||||
let (src, resolver) = resolved?;
|
let (src, resolver) = resolved?;
|
||||||
let delayed: Rc<dyn Resolver<'a, TestContextCounted>> =
|
let delayed: Rc<dyn Resolver<'a, TestContextCounted>> =
|
||||||
|
@ -6,9 +6,9 @@ use super::*;
|
|||||||
pub struct TestContextTraced;
|
pub struct TestContextTraced;
|
||||||
|
|
||||||
impl Context for TestContextTraced {
|
impl Context for TestContextTraced {
|
||||||
type T = TracedClass;
|
type T = TracedInstance;
|
||||||
|
|
||||||
type Fallible = classes::result::ResultFailOver<Self::T>;
|
type Fallible = instances::result::ResultFailOver<Self::T>;
|
||||||
|
|
||||||
type D = TracedDiagnostic;
|
type D = TracedDiagnostic;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user