From 16c939e6993831bda14a65e0cc4dab42a0b7a63c Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 18 Jun 2023 12:00:31 +0000 Subject: [PATCH] `func::weakfunctorany` --- src/func.rs | 12 +----------- src/func/class_prelude.rs | 4 ++-- src/func/controlflow.rs | 4 +++- src/func/shared.rs | 3 +-- src/func/weakfunctorany.rs | 12 ++++++++++++ 5 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 src/func/weakfunctorany.rs diff --git a/src/func.rs b/src/func.rs index 9e71f26..0921edf 100644 --- a/src/func.rs +++ b/src/func.rs @@ -21,6 +21,7 @@ pub mod shared; pub mod test_suite; #[cfg(test)] pub mod tests; +pub mod weakfunctorany; pub use self::applicative_select::{ ApplicativeSelect, ApplicativeSelectExt, Selected, SelectedWrapped, @@ -30,13 +31,6 @@ pub use self::extensions::MonadExt; #[cfg(doc)] 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`. /// /// @@ -44,10 +38,6 @@ pub trait WeakFunctor<'a>: 'a { type F: 'a; } -impl<'a, T: ?Sized + 'a + WeakFunctorAny> WeakFunctor<'a> for T { - type F = T::FAny<'a, A>; -} - pub type Wrap<'a, A, T> = >::F; /// Rust-specific implementation of [`Functor`], respecting `move` semantics. diff --git a/src/func/class_prelude.rs b/src/func/class_prelude.rs index 977f0be..696bc2a 100644 --- a/src/func/class_prelude.rs +++ b/src/func/class_prelude.rs @@ -5,9 +5,9 @@ pub use super::{ instances, local::LocalFunctor, shared::{SharedFunctor, SharedFunctorAny}, + weakfunctorany::WeakFunctorAny, Applicative, ApplicativeLA2, ApplicativeSelect, ApplicativeSelectExt, ApplicativeSeq, - ApplicativeTuple, Functor, Monad, Pure, Selected, SelectedWrapped, WeakFunctor, WeakFunctorAny, - Wrap, + ApplicativeTuple, Functor, Monad, Pure, Selected, SelectedWrapped, WeakFunctor, Wrap, }; #[cfg(test)] pub use super::{test_suite, tests}; diff --git a/src/func/controlflow.rs b/src/func/controlflow.rs index 74ddf94..da2da63 100644 --- a/src/func/controlflow.rs +++ b/src/func/controlflow.rs @@ -1,7 +1,9 @@ use std::marker::PhantomData; pub use std::ops::ControlFlow; -use super::*; +#[cfg(doc)] +use super::Monad; +use super::{weakfunctorany::WeakFunctorAny, Functor, Pure, WeakFunctor, Wrap}; pub struct ControlFlowInstance(ControlFlow<(), C>); diff --git a/src/func/shared.rs b/src/func/shared.rs index 1ffb872..d5cb8da 100644 --- a/src/func/shared.rs +++ b/src/func/shared.rs @@ -1,7 +1,6 @@ +use super::{weakfunctorany::WeakFunctorAny, WeakFunctor}; pub use radn_derive::SharedFunctorAny; -use super::*; - pub trait SharedFunctorAny: WeakFunctorAny { type SharedAny<'a, A: 'a + Clone>: 'a + Clone where diff --git a/src/func/weakfunctorany.rs b/src/func/weakfunctorany.rs new file mode 100644 index 0000000..36ee7d0 --- /dev/null +++ b/src/func/weakfunctorany.rs @@ -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 = T::FAny<'a, A>; +}