Compare commits

..

No commits in common. "b05326089d0916a9eb72442d87f46c05269d8f29" and "431b5f01f9e35f4079e07c30ee8b113f4fd4e0c9" have entirely different histories.

8 changed files with 6 additions and 44 deletions

View File

@ -5,7 +5,7 @@ use syn::{parse_macro_input, parse_quote, DeriveInput, GenericParam, Generics};
pub fn derive_shared_functor(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = input.ident;
let generics = add_clone_bounds(input.generics);
let generics = add_trait_bounds(input.generics);
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let expanded = quote! {
impl #impl_generics SharedFunctor for #name #ty_generics #where_clause {
@ -31,7 +31,7 @@ pub fn derive_shared_functor(input: proc_macro::TokenStream) -> proc_macro::Toke
proc_macro::TokenStream::from(expanded)
}
fn add_clone_bounds(mut generics: Generics) -> Generics {
fn add_trait_bounds(mut generics: Generics) -> Generics {
for param in &mut generics.params {
if let GenericParam::Type(ref mut type_param) = *param {
type_param.bounds.push(parse_quote!(Clone));
@ -39,22 +39,3 @@ fn add_clone_bounds(mut generics: Generics) -> Generics {
}
generics
}
#[proc_macro_derive(CovariantFunctor)]
pub fn derive_covariant_functor(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = input.ident;
let generics = input.generics;
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
let expanded = quote! {
impl #impl_generics CovariantFunctor for #name #ty_generics #where_clause {
fn variate<'a: 'b, 'b, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'b, A>
where
Self: 'a,
{
fa
}
}
};
proc_macro::TokenStream::from(expanded)
}

View File

@ -19,7 +19,7 @@ pub mod tests;
pub use self::istate::IState;
use self::istate::IStateClass;
pub use radn_derive::{CovariantFunctor, SharedFunctor};
pub use radn_derive::SharedFunctor;
/// Part of Haskell's `Functor f` responsible to use `f a`.
///
@ -300,9 +300,3 @@ pub trait SharedFunctor: WeakFunctor {
where
Self: 'a;
}
pub trait CovariantFunctor: WeakFunctor {
fn variate<'a: 'b, 'b, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'b, A>
where
Self: 'a;
}

View File

@ -166,14 +166,3 @@ impl<U: SharedFunctor + Functor, V: SharedFunctor> SharedFunctor for Composition
U::fmap(V::unshare, U::unshare(sa))
}
}
impl<U: CovariantFunctor + Functor, V: CovariantFunctor> CovariantFunctor
for CompositionClass<U, V>
{
fn variate<'a: 'b, 'b, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'b, A>
where
Self: 'a,
{
U::fmap(V::variate, U::variate(fa))
}
}

View File

@ -9,7 +9,6 @@ use futures::{future::Shared, join, FutureExt};
use crate::func::*;
#[derive(CovariantFunctor)]
pub struct FutureClass;
impl WeakFunctor for FutureClass {

View File

@ -11,7 +11,6 @@ use std::{cell::RefCell, rc::Rc};
use crate::func::*;
#[derive(CovariantFunctor)]
pub struct LazyClass;
impl WeakFunctor for LazyClass {

View File

@ -9,7 +9,7 @@
use crate::func::*;
#[derive(SharedFunctor, CovariantFunctor)]
#[derive(SharedFunctor)]
pub struct OptionClass;
impl WeakFunctor for OptionClass {

View File

@ -9,7 +9,7 @@
use crate::func::*;
#[derive(SharedFunctor, CovariantFunctor)]
#[derive(SharedFunctor)]
pub struct ResultClass<E>(E);
impl<E> WeakFunctor for ResultClass<E> {

View File

@ -4,7 +4,7 @@
use crate::func::*;
#[derive(SharedFunctor, CovariantFunctor)]
#[derive(SharedFunctor)]
pub struct SoloClass;
impl WeakFunctor for SoloClass {