func::weakfunctorany

This commit is contained in:
AF 2023-06-18 12:00:31 +00:00
parent 582dd76eab
commit 16c939e699
5 changed files with 19 additions and 16 deletions

View File

@ -21,6 +21,7 @@ pub mod shared;
pub mod test_suite; pub mod test_suite;
#[cfg(test)] #[cfg(test)]
pub mod tests; pub mod tests;
pub mod weakfunctorany;
pub use self::applicative_select::{ pub use self::applicative_select::{
ApplicativeSelect, ApplicativeSelectExt, Selected, SelectedWrapped, ApplicativeSelect, ApplicativeSelectExt, Selected, SelectedWrapped,
@ -30,13 +31,6 @@ pub use self::extensions::MonadExt;
#[cfg(doc)] #[cfg(doc)]
use self::instances::stackless::StacklessInstance; use self::instances::stackless::StacklessInstance;
pub trait WeakFunctorAny {
/// Type of the wrapped value.
type FAny<'a, A: 'a>: 'a
where
Self: 'a;
}
/// Part of Haskell's `Functor f` responsible for having `f a`. /// Part of Haskell's `Functor f` responsible for having `f a`.
/// ///
/// <https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-Functor.html> /// <https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-Functor.html>
@ -44,10 +38,6 @@ pub trait WeakFunctor<'a>: 'a {
type F<A: 'a>: 'a; type F<A: 'a>: 'a;
} }
impl<'a, T: ?Sized + 'a + WeakFunctorAny> WeakFunctor<'a> for T {
type F<A: 'a> = T::FAny<'a, A>;
}
pub type Wrap<'a, A, T> = <T as WeakFunctor<'a>>::F<A>; pub type Wrap<'a, A, T> = <T as WeakFunctor<'a>>::F<A>;
/// Rust-specific implementation of [`Functor`], respecting `move` semantics. /// Rust-specific implementation of [`Functor`], respecting `move` semantics.

View File

@ -5,9 +5,9 @@ pub use super::{
instances, instances,
local::LocalFunctor, local::LocalFunctor,
shared::{SharedFunctor, SharedFunctorAny}, shared::{SharedFunctor, SharedFunctorAny},
weakfunctorany::WeakFunctorAny,
Applicative, ApplicativeLA2, ApplicativeSelect, ApplicativeSelectExt, ApplicativeSeq, Applicative, ApplicativeLA2, ApplicativeSelect, ApplicativeSelectExt, ApplicativeSeq,
ApplicativeTuple, Functor, Monad, Pure, Selected, SelectedWrapped, WeakFunctor, WeakFunctorAny, ApplicativeTuple, Functor, Monad, Pure, Selected, SelectedWrapped, WeakFunctor, Wrap,
Wrap,
}; };
#[cfg(test)] #[cfg(test)]
pub use super::{test_suite, tests}; pub use super::{test_suite, tests};

View File

@ -1,7 +1,9 @@
use std::marker::PhantomData; use std::marker::PhantomData;
pub use std::ops::ControlFlow; pub use std::ops::ControlFlow;
use super::*; #[cfg(doc)]
use super::Monad;
use super::{weakfunctorany::WeakFunctorAny, Functor, Pure, WeakFunctor, Wrap};
pub struct ControlFlowInstance<C>(ControlFlow<(), C>); pub struct ControlFlowInstance<C>(ControlFlow<(), C>);

View File

@ -1,7 +1,6 @@
use super::{weakfunctorany::WeakFunctorAny, WeakFunctor};
pub use radn_derive::SharedFunctorAny; pub use radn_derive::SharedFunctorAny;
use super::*;
pub trait SharedFunctorAny: WeakFunctorAny { pub trait SharedFunctorAny: WeakFunctorAny {
type SharedAny<'a, A: 'a + Clone>: 'a + Clone type SharedAny<'a, A: 'a + Clone>: 'a + Clone
where where

View File

@ -0,0 +1,12 @@
use super::WeakFunctor;
pub trait WeakFunctorAny {
/// Type of the wrapped value.
type FAny<'a, A: 'a>: 'a
where
Self: 'a;
}
impl<'a, T: ?Sized + 'a + WeakFunctorAny> WeakFunctor<'a> for T {
type F<A: 'a> = T::FAny<'a, A>;
}