Monad lift lifetime

This commit is contained in:
AF 2023-05-26 08:52:58 +00:00
parent 859f217902
commit 906e159737
47 changed files with 361 additions and 548 deletions

View File

@ -17,7 +17,7 @@ pub trait BinaryTrees<'a>: 'a {
type Tree: 'a; type Tree: 'a;
type Key: 'a; type Key: 'a;
type T: 'a + Monad; type T: Monad<'a>;
fn split(node: Self::Node) -> Wrapped<'a, Self, Split<'a, Self>>; fn split(node: Self::Node) -> Wrapped<'a, Self, Split<'a, Self>>;
fn to_tree(node: Self::Node) -> TreeRc<'a, Self>; fn to_tree(node: Self::Node) -> TreeRc<'a, Self>;

View File

@ -51,19 +51,19 @@ pub type Split<'a, T, A, D> = (
Rc<A>, Rc<A>,
); );
pub trait TraversibleBinaryNode<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a { pub trait TraversibleBinaryNode<'a, T: Monad<'a>, A: 'a, D: 'a + PartialEq>: 'a {
fn split(&self) -> Split<'a, T, A, D>; fn split(&self) -> Split<'a, T, A, D>;
fn to_tree(self: Rc<Self>) -> Rc<dyn TraversibleBinaryTree<'a, T, A, D>>; fn to_tree(self: Rc<Self>) -> Rc<dyn TraversibleBinaryTree<'a, T, A, D>>;
} }
pub trait TraversibleBinaryReference<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a { pub trait TraversibleBinaryReference<'a, T: Monad<'a>, A: 'a, D: 'a + PartialEq>: 'a {
fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, T>; fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, T>;
/// This should be enough to compare reference for equality. /// This should be enough to compare reference for equality.
fn data(&self) -> D; fn data(&self) -> D;
} }
pub trait TraversibleBinaryTree<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a { pub trait TraversibleBinaryTree<'a, T: Monad<'a>, A: 'a, D: 'a + PartialEq>: 'a {
fn refer(&self) -> Option<Rc<dyn TraversibleBinaryReference<'a, T, A, D>>>; fn refer(&self) -> Option<Rc<dyn TraversibleBinaryReference<'a, T, A, D>>>;
} }

View File

@ -1,6 +1,6 @@
use crate::flow::traversible::*; use crate::flow::traversible::*;
pub fn n_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>( pub fn n_contains<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>, comparator: &'a dyn Comparator<A>,
n_set: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, n_set: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
key: Rc<A>, key: Rc<A>,
@ -13,7 +13,7 @@ pub fn n_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
} }
} }
pub fn r_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>( pub fn r_contains<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>, comparator: &'a dyn Comparator<A>,
r_set: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>, r_set: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>,
key: Rc<A>, key: Rc<A>,
@ -21,7 +21,7 @@ pub fn r_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
T::bind(r_set.resolve(), |n_set| n_contains(comparator, n_set, key)) T::bind(r_set.resolve(), |n_set| n_contains(comparator, n_set, key))
} }
pub fn t_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>( pub fn t_contains<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>, comparator: &'a dyn Comparator<A>,
t_set: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>, t_set: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>,
key: Rc<A>, key: Rc<A>,

View File

@ -1,6 +1,6 @@
use crate::flow::traversible::*; use crate::flow::traversible::*;
struct SubsetContext<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> { struct SubsetContext<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq> {
comparator: &'a dyn Comparator<A>, comparator: &'a dyn Comparator<A>,
n_subset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, n_subset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
n_superset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, n_superset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
@ -11,7 +11,7 @@ struct SubsetContext<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> {
k_super: Rc<A>, k_super: Rc<A>,
} }
impl<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> SubsetContext<'a, T, A, D> { impl<'a, T: 'a + MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq> SubsetContext<'a, T, A, D> {
fn on_l(self, (t_subl, t_subr, k_sub): Split<'a, T, A, D>) -> T::F<'a, ()> { fn on_l(self, (t_subl, t_subr, k_sub): Split<'a, T, A, D>) -> T::F<'a, ()> {
T::la2( T::la2(
and, and,
@ -93,7 +93,7 @@ impl<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> SubsetContext<'a, T, A
} }
} }
pub fn n_subset_of_n<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>( pub fn n_subset_of_n<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>, comparator: &'a dyn Comparator<A>,
n_subset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, n_subset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
n_superset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, n_superset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
@ -124,7 +124,7 @@ pub fn n_subset_of_n<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
.test() .test()
} }
pub fn r_subset_of_r<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>( pub fn r_subset_of_r<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>, comparator: &'a dyn Comparator<A>,
r_subset: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>, r_subset: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>,
r_superset: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>, r_superset: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>,
@ -138,7 +138,7 @@ pub fn r_subset_of_r<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
)) ))
} }
pub fn t_subset_of_t<'a, T: MonadFail<()>, A, D: 'a + PartialEq>( pub fn t_subset_of_t<'a, T: MonadFail<'a, ()>, A, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>, comparator: &'a dyn Comparator<A>,
t_subset: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>, t_subset: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>,
t_superset: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>, t_superset: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>,

View File

@ -17,7 +17,7 @@ impl PartialEq for UnbalancedData {
} }
} }
pub struct UnbalancedNode<'a, T: 'a + Monad, A: 'a> { pub struct UnbalancedNode<'a, T: Monad<'a>, A: 'a> {
cl: Rc<UnbalancedTree<'a, T, A>>, cl: Rc<UnbalancedTree<'a, T, A>>,
cr: Rc<UnbalancedTree<'a, T, A>>, cr: Rc<UnbalancedTree<'a, T, A>>,
key: Rc<A>, key: Rc<A>,
@ -25,16 +25,16 @@ pub struct UnbalancedNode<'a, T: 'a + Monad, A: 'a> {
pub type UnbalancedResolution<'a, T, A> = Wrap<'a, Rc<UnbalancedNode<'a, T, A>>, T>; pub type UnbalancedResolution<'a, T, A> = Wrap<'a, Rc<UnbalancedNode<'a, T, A>>, T>;
pub struct UnbalancedReference<'a, T: 'a + Monad, A: 'a>( pub struct UnbalancedReference<'a, T: Monad<'a>, A: 'a>(
Box<dyn 'a + Fn() -> UnbalancedResolution<'a, T, A>>, Box<dyn 'a + Fn() -> UnbalancedResolution<'a, T, A>>,
); );
pub enum UnbalancedTree<'a, T: 'a + Monad, A: 'a> { pub enum UnbalancedTree<'a, T: Monad<'a>, A: 'a> {
Leaf, Leaf,
Node(Rc<UnbalancedReference<'a, T, A>>), Node(Rc<UnbalancedReference<'a, T, A>>),
} }
impl<'a, T: 'a + Monad, A: 'a + Display> Display for UnbalancedNode<'a, T, A> impl<'a, T: Monad<'a>, A: 'a + Display> Display for UnbalancedNode<'a, T, A>
where where
UnbalancedReference<'a, T, A>: std::fmt::Display, UnbalancedReference<'a, T, A>: std::fmt::Display,
{ {
@ -43,7 +43,7 @@ where
} }
} }
impl<'a, T: 'a + Monad, A: 'a + Display> Display for UnbalancedTree<'a, T, A> impl<'a, T: Monad<'a>, A: 'a + Display> Display for UnbalancedTree<'a, T, A>
where where
UnbalancedReference<'a, T, A>: std::fmt::Display, UnbalancedReference<'a, T, A>: std::fmt::Display,
{ {
@ -72,7 +72,7 @@ impl<'a, A: 'a + Display> Display
} }
} }
impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryNode<'a, T, A, UnbalancedData> impl<'a, T: Monad<'a>, A: 'a> TraversibleBinaryNode<'a, T, A, UnbalancedData>
for UnbalancedNode<'a, T, A> for UnbalancedNode<'a, T, A>
{ {
fn split(&self) -> Split<'a, T, A, UnbalancedData> { fn split(&self) -> Split<'a, T, A, UnbalancedData> {
@ -86,7 +86,7 @@ impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryNode<'a, T, A, UnbalancedData>
} }
} }
impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryReference<'a, T, A, UnbalancedData> impl<'a, T: Monad<'a>, A: 'a> TraversibleBinaryReference<'a, T, A, UnbalancedData>
for UnbalancedReference<'a, T, A> for UnbalancedReference<'a, T, A>
{ {
fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, UnbalancedData>>, T> { fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, UnbalancedData>>, T> {
@ -101,7 +101,7 @@ impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryReference<'a, T, A, UnbalancedDa
} }
} }
impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryTree<'a, T, A, UnbalancedData> impl<'a, T: Monad<'a>, A: 'a> TraversibleBinaryTree<'a, T, A, UnbalancedData>
for UnbalancedTree<'a, T, A> for UnbalancedTree<'a, T, A>
{ {
fn refer(&self) -> Option<Rc<dyn TraversibleBinaryReference<'a, T, A, UnbalancedData>>> { fn refer(&self) -> Option<Rc<dyn TraversibleBinaryReference<'a, T, A, UnbalancedData>>> {
@ -116,11 +116,11 @@ type WrapType<'a, T, A> = Box<
dyn 'a + Fn(Rc<UnbalancedNode<'a, T, A>>) -> Box<dyn Fn() -> UnbalancedResolution<'a, T, A>>, dyn 'a + Fn(Rc<UnbalancedNode<'a, T, A>>) -> Box<dyn Fn() -> UnbalancedResolution<'a, T, A>>,
>; >;
pub struct UnbalancedConstructor<'a, T: 'a + Monad, A: 'a> { pub struct UnbalancedConstructor<'a, T: Monad<'a>, A: 'a> {
wrap: WrapType<'a, T, A>, wrap: WrapType<'a, T, A>,
} }
impl<'a, T: 'a + Monad, A: 'a> UnbalancedConstructor<'a, T, A> { impl<'a, T: Monad<'a>, A: 'a> UnbalancedConstructor<'a, T, A> {
pub fn rc(wrap: WrapType<'a, T, A>) -> Rc<Self> { pub fn rc(wrap: WrapType<'a, T, A>) -> Rc<Self> {
Self { wrap }.into() Self { wrap }.into()
} }

View File

@ -45,7 +45,7 @@ pub trait WeakFunctorA<'a>: 'a {
type Fa<A: 'a>: 'a; type Fa<A: 'a>: 'a;
} }
impl<'a, T: 'a + WeakFunctor> WeakFunctorA<'a> for T { impl<'a, T: ?Sized + 'a + WeakFunctor> WeakFunctorA<'a> for T {
type Fa<A: 'a> = T::F<'a, A>; type Fa<A: 'a> = T::F<'a, A>;
} }
@ -184,35 +184,28 @@ pub trait Applicative:
/// Equivalent of Haskell's `Monad`. /// Equivalent of Haskell's `Monad`.
/// ///
/// <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>
pub trait Monad: Applicative { pub trait Monad<'a>: 'a + Applicative {
/// Equivalent of Haskell's `>==`. /// Equivalent of Haskell's `>==`.
/// Due to Rust limitations, it's not a `function->function` conversion. /// Due to Rust limitations, it's not a `function->function` conversion.
/// For that see [`derivations::bind`]. /// For that see [`derivations::bind`].
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> ) -> Self::F<'a, B>;
where
Self: 'a;
/// 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 [`StacklessInstance::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<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>;
where
Self: 'a;
/// Equivalent of Haskell's `join`. /// Equivalent of Haskell's `join`.
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
where
Self: 'a,
{
Self::bind(ffa, |fa| fa) Self::bind(ffa, |fa| fa)
} }
} }
pub trait MonadExt<'a>: 'a + Monad { pub trait MonadExt<'a>: Monad<'a> {
/// [`FnMut`] version of [`Monad::iterate`]. /// [`FnMut`] version of [`Monad::iterate`].
/// Reasoning for this method existing at all is that /// Reasoning for this method existing at all is that
/// most usecases are better modelled with [`FnMut`] /// most usecases are better modelled with [`FnMut`]
@ -225,23 +218,20 @@ pub trait MonadExt<'a>: 'a + Monad {
} }
} }
impl<'a, T: 'a + Monad> MonadExt<'a> for T {} impl<'a, T: Monad<'a>> MonadExt<'a> for T {}
/// Part of [`MonadFail`] responsible for Haskell's `fail`. /// Part of [`MonadFail`] responsible for Haskell's `fail`.
pub trait Fail<E>: WeakFunctor { pub trait Fail<'a, E: 'a>: 'a + WeakFunctor {
/// Equivalent of Haskell's `fail`. /// Equivalent of Haskell's `fail`.
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A> fn fail<A: 'a>(e: E) -> Self::F<'a, A>;
where
Self: 'a,
E: 'a;
} }
/// Equivalent of Haskell's `MonadFail`. Auto-implemented for all [`Fail`]`+`[`Monad`]. /// Equivalent of Haskell's `MonadFail`. Auto-implemented for all [`Fail`]`+`[`Monad`].
/// ///
/// <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>
pub trait MonadFail<E>: Monad + Fail<E> {} pub trait MonadFail<'a, E: 'a>: Monad<'a> + Fail<'a, E> {}
impl<E, T: Monad + Fail<E>> MonadFail<E> for T {} impl<'a, E: 'a, T: Monad<'a> + Fail<'a, E>> MonadFail<'a, E> for T {}
/// Represents wrapped results which are instantly available. /// Represents wrapped results which are instantly available.
pub trait LocalFunctor: WeakFunctor { pub trait LocalFunctor: WeakFunctor {
@ -262,40 +252,32 @@ pub trait LocalFunctor: WeakFunctor {
} }
/// Represents a (collection of) [Monad]\(s) that can hold any type of error. /// Represents a (collection of) [Monad]\(s) that can hold any type of error.
pub trait MonadFailAny { pub trait MonadFailAny<'a>: 'a {
/// [`MonadFail`] for a specific error type. /// [`MonadFail`] for a specific error type.
type W<E>: MonadFail<E>; type W<E>: MonadFail<'a, E>
where
E: 'a;
/// Associated infallible [`Monad`]. /// Associated infallible [`Monad`].
type T: Monad; type T: Monad<'a>;
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>;
where
Self: 'a;
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>;
where
Self: 'a;
/// Equivalent of [`Result::map_err`]. /// Equivalent of [`Result::map_err`].
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( fn map_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> E1, f: impl 'a + FnOnce(E0) -> E1,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
Self::bind_err(wa, |e0| Self::fail(f(e0))) Self::bind_err(wa, |e0| Self::fail(f(e0)))
} }
/// Equivalent of `catch`/`except`. To inject errors on success, see [`MonadFailAny::bind`]. /// Equivalent of `catch`/`except`. To inject errors on success, see [`MonadFailAny::bind`].
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>( fn bind_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>, f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
Self::bind(wa, |result| match result { Self::bind(wa, |result| match result {
Ok(a) => Self::pure(a), Ok(a) => Self::pure(a),
Err(e0) => f(e0), Err(e0) => f(e0),
@ -307,13 +289,10 @@ pub trait MonadFailAny {
/// ///
/// Note: Reasonably it is expected to lack fail semantics for the underlying result. /// Note: Reasonably it is expected to lack fail semantics for the underlying result.
/// Therefore the default implementation descends into the non-fail monad [`MonadFailAny::T`]. /// Therefore the default implementation descends into the non-fail monad [`MonadFailAny::T`].
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>( fn bind<A: 'a, B: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>, f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
) -> WrapE<'a, B, E1, Self> ) -> WrapE<'a, B, E1, Self> {
where
Self: 'a,
{
Self::stuff(<Self::T as Monad>::bind(Self::unstuff(wa), |result| { Self::stuff(<Self::T as Monad>::bind(Self::unstuff(wa), |result| {
Self::unstuff(f(result)) Self::unstuff(f(result))
})) }))
@ -322,12 +301,9 @@ pub trait MonadFailAny {
/// Equivalent of [`Monad::join`], flattening the errors. /// Equivalent of [`Monad::join`], flattening the errors.
/// ///
/// Note: default implementation doesn't depend on [`Monad::join`]. /// Note: default implementation doesn't depend on [`Monad::join`].
fn join<'a, A: 'a, E0: 'a, E1: 'a>( fn join<A: 'a, E0: 'a, E1: 'a>(
wwa: WrapE<'a, WrapE<'a, A, E0, Self>, E1, Self>, wwa: WrapE<'a, WrapE<'a, A, E0, Self>, E1, Self>,
) -> WrapE<'a, A, Result<E0, E1>, Self> ) -> WrapE<'a, A, Result<E0, E1>, Self> {
where
Self: 'a,
{
Self::bind(wwa, |result| match result { Self::bind(wwa, |result| match result {
Ok(wa) => Self::map_err(wa, Ok), Ok(wa) => Self::map_err(wa, Ok),
Err(e1) => Self::fail(Err(e1)), Err(e1) => Self::fail(Err(e1)),
@ -335,12 +311,9 @@ pub trait MonadFailAny {
} }
/// Lift the error. /// Lift the error.
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>( fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>, wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self> ) -> WrapE<'a, A, Result<E1, E0>, Self> {
where
Self: 'a,
{
<Self::W<Result<E1, E0>> as Monad>::bind(Self::map_err(wa, Err), |fa| match fa { <Self::W<Result<E1, E0>> as Monad>::bind(Self::map_err(wa, Err), |fa| match fa {
Ok(a) => Self::pure(a), Ok(a) => Self::pure(a),
Err(e) => Self::fail(Ok(e)), Err(e) => Self::fail(Ok(e)),
@ -348,9 +321,9 @@ pub trait MonadFailAny {
} }
} }
pub type WrapE<'a, A, E, Fallible> = Wrap<'a, A, <Fallible as MonadFailAny>::W<E>>; pub type WrapE<'a, A, E, Fallible> = Wrap<'a, A, <Fallible as MonadFailAny<'a>>::W<E>>;
pub trait MonadFailAnyExt<'a>: 'a + MonadFailAny { pub trait MonadFailAnyExt<'a>: MonadFailAny<'a> {
fn pure<E: 'a, A: 'a>(a: A) -> WrapE<'a, A, E, Self> { fn pure<E: 'a, A: 'a>(a: A) -> WrapE<'a, A, E, Self> {
<Self::W<E> as Pure>::pure(a) <Self::W<E> as Pure>::pure(a)
} }
@ -367,7 +340,7 @@ pub trait MonadFailAnyExt<'a>: 'a + MonadFailAny {
} }
} }
impl<'a, Fallible: ?Sized + 'a + MonadFailAny> MonadFailAnyExt<'a> for Fallible {} impl<'a, Fallible: ?Sized + MonadFailAny<'a>> MonadFailAnyExt<'a> for Fallible {}
pub trait SharedFunctor: WeakFunctor { pub trait SharedFunctor: WeakFunctor {
type Shared<'a, A: 'a + Clone>: 'a + Clone type Shared<'a, A: 'a + Clone>: 'a + Clone

View File

@ -10,7 +10,7 @@ pub fn fmap<'a, T: 'a + Functor, A: 'a, B: 'a>(
} }
/// Equivalent of Haskell's `fmap`. `function-function` equivalent of [Monad::bind]. /// Equivalent of Haskell's `fmap`. `function-function` equivalent of [Monad::bind].
pub fn bind<'a, T: 'a + Monad, A: 'a, B: 'a>( pub fn bind<'a, T: Monad<'a>, A: 'a, B: 'a>(
f: impl 'a + FnOnce(A) -> T::F<'a, B>, f: impl 'a + FnOnce(A) -> T::F<'a, B>,
) -> impl FnOnce(T::F<'a, A>) -> T::F<'a, B> { ) -> impl FnOnce(T::F<'a, A>) -> T::F<'a, B> {
move |fa| T::bind(fa, f) move |fa| T::bind(fa, f)

View File

@ -106,29 +106,19 @@ impl<U: Applicative, V: Applicative> Applicative for CompositionInstance<U, V> {
} }
} }
impl<U: Monad, V: Monad + LocalFunctor> Monad for CompositionInstance<U, V> { impl<'a, U: Monad<'a>, V: Monad<'a> + LocalFunctor> Monad<'a> for CompositionInstance<U, V> {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> ) -> Self::F<'a, B> {
where
Self: 'a,
{
U::bind(fa, |ua| U::fmap(V::join, V::stuff::<_, U>(V::fmap(f, ua)))) U::bind(fa, |ua| U::fmap(V::join, V::stuff::<_, U>(V::fmap(f, ua))))
} }
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
U::iterate(ComposedIterative(f)) U::iterate(ComposedIterative(f))
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
where
Self::F<'a, A>: 'a,
Self: 'a,
{
U::join(U::fmap(|ufa| U::fmap(V::join, V::stuff::<_, U>(ufa)), ffa)) U::join(U::fmap(|ufa| U::fmap(V::join, V::stuff::<_, U>(ufa)), ffa))
} }
} }
@ -137,8 +127,8 @@ struct ComposedIterative<F>(F);
impl< impl<
'a, 'a,
U: 'a + Monad, U: Monad<'a>,
V: 'a + Monad + LocalFunctor, V: Monad<'a> + LocalFunctor,
F: Iterative<'a, T = CompositionInstance<U, V>>, F: Iterative<'a, T = CompositionInstance<U, V>>,
> Iterative<'a> for ComposedIterative<F> > Iterative<'a> for ComposedIterative<F>
{ {
@ -157,12 +147,10 @@ impl<
} }
} }
impl<E, U: Monad, V: Fail<E> + LocalFunctor> Fail<E> for CompositionInstance<U, V> { impl<'a, E: 'a, U: Monad<'a>, V: Fail<'a, E> + LocalFunctor> Fail<'a, E>
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A> for CompositionInstance<U, V>
where {
Self: 'a, fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
E: 'a,
{
U::pure(V::fail(e)) U::pure(V::fail(e))
} }
} }

View File

@ -136,21 +136,15 @@ impl<E: Effect> Applicative for EffectInstance<E> {
} }
} }
impl<E: Effect> Monad for EffectInstance<E> { impl<'a, E: 'a + Effect> Monad<'a> for EffectInstance<E> {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> ) -> Self::F<'a, B> {
where
Self: 'a,
{
f(fa.value).e_after(fa.effect) f(fa.value).e_after(fa.effect)
} }
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
let mut effect = E::e_pure(); let mut effect = E::e_pure();
loop { loop {
let fa = f.next(); let fa = f.next();
@ -162,11 +156,7 @@ impl<E: Effect> Monad for EffectInstance<E> {
} }
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
where
Self::F<'a, A>: 'a,
Self: 'a,
{
ffa.value.e_after(ffa.effect) ffa.value.e_after(ffa.effect)
} }
} }

View File

@ -99,18 +99,15 @@ impl Applicative for FutureInstance {
} }
} }
impl Monad for FutureInstance { impl<'a> Monad<'a> for FutureInstance {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> { ) -> Self::F<'a, B> {
Box::pin(async { f(fa.await).await }) Box::pin(async { f(fa.await).await })
} }
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
Box::pin(async move { Box::pin(async move {
loop { loop {
match f.next().await { match f.next().await {
@ -121,7 +118,7 @@ impl Monad for FutureInstance {
}) })
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> { fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
Box::pin(async { ffa.await.await }) Box::pin(async { ffa.await.await })
} }
} }

View File

@ -82,18 +82,15 @@ impl Applicative for LazyInstance {
} }
} }
impl Monad for LazyInstance { impl<'a> Monad<'a> for LazyInstance {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> { ) -> Self::F<'a, B> {
Box::new(|| f(fa())()) Box::new(|| f(fa())())
} }
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
loop { loop {
match f.next()() { match f.next()() {
ControlFlow::Continue(next_f) => f = next_f, ControlFlow::Continue(next_f) => f = next_f,
@ -102,7 +99,7 @@ impl Monad for LazyInstance {
} }
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> { fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
Box::new(|| ffa()()) Box::new(|| ffa()())
} }
} }

View File

@ -86,18 +86,15 @@ impl Applicative for OptionInstance {
} }
} }
impl Monad for OptionInstance { impl<'a> Monad<'a> for OptionInstance {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> { ) -> Self::F<'a, B> {
f(fa?) f(fa?)
} }
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
loop { loop {
match f.next()? { match f.next()? {
ControlFlow::Continue(next_f) => f = next_f, ControlFlow::Continue(next_f) => f = next_f,
@ -106,7 +103,7 @@ impl Monad for OptionInstance {
} }
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> { fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
ffa? ffa?
} }
} }
@ -136,11 +133,8 @@ impl LocalFunctor for OptionInstance {
} }
} }
impl Fail<()> for OptionInstance { impl<'a> Fail<'a, ()> for OptionInstance {
fn fail<'a, A: 'a>(_e: ()) -> Self::F<'a, A> fn fail<A: 'a>(_e: ()) -> Self::F<'a, A> {
where
Self: 'a,
{
None None
} }
} }

View File

@ -110,7 +110,7 @@ impl<F, O> OverloadIterative<F, O> {
} }
} }
impl<'a, T: 'a + Monad, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadInstance<T, O>>> impl<'a, T: Monad<'a>, 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,29 +128,19 @@ impl<'a, T: 'a + Monad, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadInstan
} }
} }
impl<T: Monad, O: DeriveMonad> Monad for OverloadInstance<T, O> { impl<'a, T: Monad<'a>, O: 'a + DeriveMonad> Monad<'a> for OverloadInstance<T, O> {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> ) -> Self::F<'a, B> {
where
Self: 'a,
{
T::bind(fa, f) T::bind(fa, f)
} }
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
T::iterate(OverloadIterative::new(f)) T::iterate(OverloadIterative::new(f))
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
where
Self::F<'a, A>: 'a,
Self: 'a,
{
T::join(ffa) T::join(ffa)
} }
} }
@ -159,39 +149,29 @@ 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 OverloadInstance<T, DeriveFail<Ex>> { impl<'a, E: 'a, Ex: 'a, T: MonadFail<'a, Result<E, Ex>>> Fail<'a, E>
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A> for OverloadInstance<T, DeriveFail<Ex>>
where {
Self: 'a, fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
E: 'a,
{
T::fail(Ok(e)) T::fail(Ok(e))
} }
} }
struct DeriveFailAny<Ex, Fallible>(Ex, Fallible); struct DeriveFailAny<Ex, Fallible>(Ex, Fallible);
impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> { impl<'a, Ex: 'a, Fallible: MonadFailAny<'a>> MonadFailAny<'a> for DeriveFailAny<Ex, Fallible> {
type W<E> = OverloadInstance<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>; type W<E: 'a> = OverloadInstance<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>;
type T = Fallible::W<Ex>; type T = Fallible::W<Ex>;
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
where
Self: 'a,
Fallible::W<Ex>: 'a,
{
Fallible::bind_err(<Self::W<E> as Functor>::fmap(Ok, wa), |err| match err { Fallible::bind_err(<Self::W<E> as Functor>::fmap(Ok, wa), |err| match err {
Ok(e) => Fallible::pure(Err(e)), Ok(e) => Fallible::pure(Err(e)),
Err(ex) => Fallible::fail(ex), Err(ex) => Fallible::fail(ex),
}) })
} }
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
where
Self: 'a,
Fallible::W<Ex>: 'a,
{
Fallible::bind(fa, |result| match result { Fallible::bind(fa, |result| match result {
Ok(Ok(a)) => Fallible::pure(a), Ok(Ok(a)) => Fallible::pure(a),
Ok(Err(e)) => Fallible::fail(Ok(e)), Ok(Err(e)) => Fallible::fail(Ok(e)),
@ -199,36 +179,27 @@ impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
}) })
} }
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( fn map_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> E1, f: impl 'a + FnOnce(E0) -> E1,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
Fallible::map_err(wa, |err| err.map(f)) Fallible::map_err(wa, |err| err.map(f))
} }
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>( fn bind_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>, f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
Fallible::bind_err(wa, |err| match err { Fallible::bind_err(wa, |err| match err {
Ok(e0) => f(e0), Ok(e0) => f(e0),
Err(ex) => Fallible::fail(Err(ex)), Err(ex) => Fallible::fail(Err(ex)),
}) })
} }
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>( fn bind<A: 'a, B: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>, f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
) -> WrapE<'a, B, E1, Self> ) -> WrapE<'a, B, E1, Self> {
where
Self: 'a,
{
Fallible::bind(wa, |result| match result { Fallible::bind(wa, |result| match result {
Ok(a) => f(Ok(a)), Ok(a) => f(Ok(a)),
Err(Ok(e0)) => f(Err(e0)), Err(Ok(e0)) => f(Err(e0)),

View File

@ -104,21 +104,15 @@ impl<E> Applicative for ResultInstance<E> {
} }
} }
impl<E> Monad for ResultInstance<E> { impl<'a, E: 'a> Monad<'a> for ResultInstance<E> {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> ) -> Self::F<'a, B> {
where
Self: 'a,
{
f(fa?) f(fa?)
} }
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
loop { loop {
match f.next()? { match f.next()? {
ControlFlow::Continue(next_f) => f = next_f, ControlFlow::Continue(next_f) => f = next_f,
@ -127,10 +121,7 @@ impl<E> Monad for ResultInstance<E> {
} }
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
where
Self: 'a,
{
ffa? ffa?
} }
} }
@ -160,11 +151,8 @@ impl<E> LocalFunctor for ResultInstance<E> {
} }
} }
impl<E> Fail<E> for ResultInstance<E> { impl<'a, E: 'a> Fail<'a, E> for ResultInstance<E> {
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A> fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
where
Self: 'a,
{
Err(e) Err(e)
} }
} }
@ -184,61 +172,43 @@ impl<'a, A: 'a, E0: 'a> ResultExt<'a, A, E0> for Result<A, E0> {
} }
} }
impl MonadFailAny for ResultFailAny { impl<'a> MonadFailAny<'a> for ResultFailAny {
type W<E> = ResultInstance<E>; type W<E: 'a> = ResultInstance<E>;
type T = instances::solo::SoloInstance; type T = instances::solo::SoloInstance;
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
where
Self: 'a,
{
wa wa
} }
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
where
Self: 'a,
{
fa fa
} }
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( fn map_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> E1, f: impl 'a + FnOnce(E0) -> E1,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
wa.map_err(f) wa.map_err(f)
} }
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>( fn bind_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>, f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
wa.bind_err(f) wa.bind_err(f)
} }
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>( fn bind<A: 'a, B: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>, f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
) -> WrapE<'a, B, E1, Self> ) -> WrapE<'a, B, E1, Self> {
where
Self: 'a,
{
f(wa) f(wa)
} }
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>( fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>, wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self> ) -> WrapE<'a, A, Result<E1, E0>, Self> {
where
Self: 'a,
{
match wa { match wa {
Ok(Ok(a)) => Ok(a), Ok(Ok(a)) => Ok(a),
Ok(Err(e)) => Err(Ok(e)), Ok(Err(e)) => Err(Ok(e)),
@ -247,66 +217,48 @@ impl MonadFailAny for ResultFailAny {
} }
} }
pub struct ResultFailOver<T: Monad>(T); pub struct ResultFailOver<T>(T);
impl<T: Monad> MonadFailAny for ResultFailOver<T> { impl<'a, T: Monad<'a>> MonadFailAny<'a> for ResultFailOver<T> {
type W<E> = super::composition::CompositionInstance<T, ResultInstance<E>>; type W<E: 'a> = super::composition::CompositionInstance<T, ResultInstance<E>>;
type T = T; type T = T;
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
where
Self: 'a,
{
wa wa
} }
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
where
Self: 'a,
{
fa fa
} }
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( fn map_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> E1, f: impl 'a + FnOnce(E0) -> E1,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
T::fmap(|a| a.map_err(f), wa) T::fmap(|a| a.map_err(f), wa)
} }
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>( fn bind_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>, f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
T::bind(wa, |a| match a { T::bind(wa, |a| match a {
Ok(a) => T::pure(Ok(a)), Ok(a) => T::pure(Ok(a)),
Err(e) => f(e), Err(e) => f(e),
}) })
} }
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>( fn bind<A: 'a, B: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>, f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
) -> WrapE<'a, B, E1, Self> ) -> WrapE<'a, B, E1, Self> {
where
Self: 'a,
{
T::bind(wa, f) T::bind(wa, f)
} }
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>( fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>, wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self> ) -> WrapE<'a, A, Result<E1, E0>, Self> {
where
Self: 'a,
{
T::fmap(<ResultFailAny as MonadFailAny>::rotate_out, wa) T::fmap(<ResultFailAny as MonadFailAny>::rotate_out, wa)
} }
} }

View File

@ -74,18 +74,15 @@ impl Applicative for SoloInstance {
} }
} }
impl Monad for SoloInstance { impl<'a> Monad<'a> for SoloInstance {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> { ) -> Self::F<'a, B> {
f(fa) f(fa)
} }
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
loop { loop {
match f.next() { match f.next() {
ControlFlow::Continue(next_f) => f = next_f, ControlFlow::Continue(next_f) => f = next_f,
@ -94,7 +91,7 @@ impl Monad for SoloInstance {
} }
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> { fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
ffa ffa
} }
} }
@ -117,12 +114,8 @@ impl LocalFunctor for SoloInstance {
} }
} }
impl Fail<std::convert::Infallible> for SoloInstance { impl<'a> Fail<'a, std::convert::Infallible> for SoloInstance {
fn fail<'a, A: 'a>(e: std::convert::Infallible) -> Self::F<'a, A> fn fail<A: 'a>(e: std::convert::Infallible) -> Self::F<'a, A> {
where
Self: 'a,
std::convert::Infallible: 'a,
{
match e {} match e {}
} }
} }

View File

@ -215,21 +215,15 @@ impl Applicative for StacklessInstance {
} }
} }
impl Monad for StacklessInstance { impl<'a> Monad<'a> for StacklessInstance {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> ) -> Self::F<'a, B> {
where
Self: 'a,
{
fa.bind(f) fa.bind(f)
} }
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
Self::pure(()).bind(move |_| { Self::pure(()).bind(move |_| {
f.next().bind(|state| match state { f.next().bind(|state| match state {
ControlFlow::Continue(next_f) => Self::iterate(next_f), ControlFlow::Continue(next_f) => Self::iterate(next_f),
@ -238,11 +232,7 @@ impl Monad for StacklessInstance {
}) })
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
where
Self::F<'a, A>: 'a,
Self: 'a,
{
Stackless(Box::new(|takesa| { Stackless(Box::new(|takesa| {
let lcell = Rc::new(Cell::new(None)); let lcell = Rc::new(Cell::new(None));
let rcell = lcell.clone(); let rcell = lcell.clone();

View File

@ -117,21 +117,15 @@ impl<E> Applicative for TryFutureInstance<E> {
} }
} }
impl<E> Monad for TryFutureInstance<E> { impl<'a, E: 'a> Monad<'a> for TryFutureInstance<E> {
fn bind<'a, A: 'a, B: 'a>( fn bind<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>,
) -> Self::F<'a, B> ) -> Self::F<'a, B> {
where
Self: 'a,
{
Box::pin(async { f(fa.await?).await }) Box::pin(async { f(fa.await?).await })
} }
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
where
Self: 'a,
{
Box::pin(async move { Box::pin(async move {
loop { loop {
match f.next().await? { match f.next().await? {
@ -142,10 +136,7 @@ impl<E> Monad for TryFutureInstance<E> {
}) })
} }
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
where
Self: 'a,
{
Box::pin(async { ffa.await?.await }) Box::pin(async { ffa.await?.await })
} }
} }
@ -170,54 +161,38 @@ impl<E: Clone> SharedFunctor for TryFutureInstance<E> {
} }
} }
impl<E> Fail<E> for TryFutureInstance<E> { impl<'a, E: 'a> Fail<'a, E> for TryFutureInstance<E> {
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A> fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
where
Self: 'a,
E: 'a,
{
Box::pin(async { Err(e) }) Box::pin(async { Err(e) })
} }
} }
pub struct FutureFailAny; pub struct FutureFailAny;
impl MonadFailAny for FutureFailAny { impl<'a> MonadFailAny<'a> for FutureFailAny {
type W<E> = TryFutureInstance<E>; type W<E: 'a> = TryFutureInstance<E>;
type T = instances::future::FutureInstance; type T = instances::future::FutureInstance;
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
where
Self: 'a,
{
wa wa
} }
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
where
Self: 'a,
{
fa fa
} }
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( fn map_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> E1, f: impl 'a + FnOnce(E0) -> E1,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
Box::pin(async { wa.await.map_err(f) }) Box::pin(async { wa.await.map_err(f) })
} }
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>( fn bind_err<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>, f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
) -> WrapE<'a, A, E1, Self> ) -> WrapE<'a, A, E1, Self> {
where
Self: 'a,
{
Box::pin(async { Box::pin(async {
match wa.await { match wa.await {
Ok(a) => Ok(a), Ok(a) => Ok(a),
@ -226,22 +201,16 @@ impl MonadFailAny for FutureFailAny {
}) })
} }
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>( fn bind<A: 'a, B: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, A, E0, Self>, wa: WrapE<'a, A, E0, Self>,
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>, f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
) -> WrapE<'a, B, E1, Self> ) -> WrapE<'a, B, E1, Self> {
where
Self: 'a,
{
Box::pin(async { f(wa.await).await }) Box::pin(async { f(wa.await).await })
} }
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>( fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>, wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self> ) -> WrapE<'a, A, Result<E1, E0>, Self> {
where
Self: 'a,
{
Box::pin(async { Box::pin(async {
match wa.await { match wa.await {
Ok(Ok(a)) => Ok(a), Ok(Ok(a)) => Ok(a),

View File

@ -1,11 +1,11 @@
use super::*; use super::*;
type Frwa<'a, A, E0, E1, Fallible> = type Frwa<'a, A, E0, E1, Fallible> =
Wrap<'a, Result<WrapE<'a, A, E0, Fallible>, E1>, <Fallible as MonadFailAny>::T>; Wrap<'a, Result<WrapE<'a, A, E0, Fallible>, E1>, <Fallible as MonadFailAny<'a>>::T>;
type Wwa<'a, A, E0, E1, Fallible> = WrapE<'a, WrapE<'a, A, E0, Fallible>, E1, Fallible>; type Wwa<'a, A, E0, E1, Fallible> = WrapE<'a, WrapE<'a, A, E0, Fallible>, E1, Fallible>;
pub trait SpeculativeFail<'a>: 'a + MonadFailAny { pub trait SpeculativeFail<'a>: MonadFailAny<'a> {
fn _speculative_a_wb<A: 'a, B: 'a, E0: 'a, E1: 'a>( fn _speculative_a_wb<A: 'a, B: 'a, E0: 'a, E1: 'a>(
a: A, a: A,
wb: WrapE<'a, B, E0, Self>, wb: WrapE<'a, B, E0, Self>,
@ -101,4 +101,4 @@ pub trait SpeculativeFail<'a>: 'a + MonadFailAny {
} }
} }
impl<'a, Fallible: ?Sized + 'a + MonadFailAny> SpeculativeFail<'a> for Fallible {} impl<'a, Fallible: ?Sized + MonadFailAny<'a>> SpeculativeFail<'a> for Fallible {}

View File

@ -55,8 +55,7 @@ pub fn applicative_follows_laws<T: Applicative + FunctorTestSuite>() -> R {
res res
} }
pub fn monad_follows_laws<T: Monad + FunctorTestSuite>() -> R pub fn monad_follows_laws<'a, T: Monad<'a> + FunctorTestSuite>() -> R {
where {
let mut res = applicative_follows_laws::<T>(); let mut res = applicative_follows_laws::<T>();
T::sample(|pa| { T::sample(|pa| {
res += bind_respects_left_identity::<T, _, _>(|x| pa(x + 3), || 2); res += bind_respects_left_identity::<T, _, _>(|x| pa(x + 3), || 2);

View File

@ -232,7 +232,7 @@ pub fn discard_can_be_expressed_via_seq_or_la2<
) )
} }
pub fn bind_respects_left_identity<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a + Debug + PartialEq>( pub fn bind_respects_left_identity<'a, T: Monad<'a> + Eqr, A: 'a, B: 'a + Debug + PartialEq>(
f: impl 'a + Fn(A) -> T::F<'a, B>, f: impl 'a + Fn(A) -> T::F<'a, B>,
a0: impl Fn() -> A, a0: impl Fn() -> A,
) -> R { ) -> R {
@ -243,7 +243,7 @@ pub fn bind_respects_left_identity<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a + Debug
) )
} }
pub fn bind_respects_right_identity<'a, T: 'a + Monad + Eqr, A: 'a + Debug + PartialEq>( pub fn bind_respects_right_identity<'a, T: Monad<'a> + Eqr, A: 'a + Debug + PartialEq>(
fa0: impl Fn() -> T::F<'a, A>, fa0: impl Fn() -> T::F<'a, A>,
) -> R { ) -> R {
T::eqr( T::eqr(
@ -253,7 +253,7 @@ pub fn bind_respects_right_identity<'a, T: 'a + Monad + Eqr, A: 'a + Debug + Par
) )
} }
pub fn bind_is_associative<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a, C: 'a + Debug + PartialEq>( pub fn bind_is_associative<'a, T: Monad<'a> + Eqr, A: 'a, B: 'a, C: 'a + Debug + PartialEq>(
f: impl 'a + Clone + Fn(B) -> T::F<'a, C>, f: impl 'a + Clone + Fn(B) -> T::F<'a, C>,
g: impl 'a + Clone + Fn(A) -> T::F<'a, B>, g: impl 'a + Clone + Fn(A) -> T::F<'a, B>,
fa0: impl 'a + Fn() -> T::F<'a, A>, fa0: impl 'a + Fn() -> T::F<'a, A>,
@ -267,7 +267,7 @@ pub fn bind_is_associative<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a, C: 'a + Debug
pub fn seq_can_be_expressed_via_bind< pub fn seq_can_be_expressed_via_bind<
'a, 'a,
T: 'a + Monad + Eqr, T: Monad<'a> + Eqr,
A: 'a, A: 'a,
B: 'a + Debug + PartialEq, B: 'a + Debug + PartialEq,
F: 'a + Fn(A) -> B, F: 'a + Fn(A) -> B,
@ -282,7 +282,7 @@ pub fn seq_can_be_expressed_via_bind<
) )
} }
pub fn fmap_can_be_expressed_via_bind<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a + Debug + PartialEq>( pub fn fmap_can_be_expressed_via_bind<'a, T: Monad<'a> + Eqr, A: 'a, B: 'a + Debug + PartialEq>(
f: impl 'a + Copy + Fn(A) -> B, f: impl 'a + Copy + Fn(A) -> B,
fa0: impl 'a + Fn() -> T::F<'a, A>, fa0: impl 'a + Fn() -> T::F<'a, A>,
) -> R { ) -> R {

View File

@ -26,39 +26,45 @@ pub use self::serialization::*;
pub use self::slice_deserializer::*; pub use self::slice_deserializer::*;
/// Basic support for tracing events across the execution. /// Basic support for tracing events across the execution.
pub trait Diagnostic<T: Monad> { pub trait Diagnostic<'a, T: Monad<'a>> {
/// Specify that the evaluation happens after a specific event. /// Specify that the evaluation happens after a specific event.
fn after<'a: 'b, 'b, A>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>; fn after<'b, A: 'a>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>
where
'a: 'b;
/// Specify that the evaluation happens before a specific event. /// Specify that the evaluation happens before a specific event.
fn before<'a: 'b, 'b, A>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>; fn before<'b, A: 'a>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>
where
'a: 'b;
/// Label the evaluation step as a specific named action. /// Label the evaluation step as a specific named action.
fn wrapped<'a: 'b, 'b, A>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>; fn wrapped<'b, A: 'a>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>
where
'a: 'b;
} }
/// Execution context. /// Execution context.
pub trait Context { pub trait Context<'a>: 'a {
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]). /// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
type T: Monad; type T: Monad<'a>;
/// Type to allow improved support for result evaluation. /// Type to allow improved support for result evaluation.
/// This is important for async applications stopping early. /// This is important for async applications stopping early.
type Fallible: MonadFailAny<T = Self::T>; type Fallible: MonadFailAny<'a, T = Self::T>;
/// See [`Diagnostic`]. /// See [`Diagnostic`].
type D: Diagnostic<Self::T>; type D: Diagnostic<'a, Self::T>;
/// Type to represent resolution errors mainly arising in [`Resolver::resolve`]. /// Type to represent resolution errors mainly arising in [`Resolver::resolve`].
type LookupError<'a>: 'a + Error; type LookupError: 'a + Error;
/// Get [type@Hash] of a slice, mostly for use in [`Point`]. /// Get [type@Hash] of a slice, mostly for use in [`Point`].
fn hash(s: &[u8]) -> Hash; fn hash(s: &[u8]) -> Hash;
} }
/// Helper alias for [`WeakFunctor::F`] of [`Context::T`]. /// Helper alias for [`WeakFunctor::F`] of [`Context::T`].
pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context>::T>; pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context<'a>>::T>;
/// Fundamental trait for ADN objects. /// Fundamental trait for ADN objects.
pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable { pub trait Mentionable<'a, Ctx: Context<'a>>: 'a + Serializable {
/// Type of the associated factory. /// Type of the associated factory.
type Fctr: Factory<'a, Ctx, Mtbl = Self>; type Fctr: Factory<'a, Ctx, Mtbl = Self>;
@ -83,7 +89,7 @@ pub type ParseResult<'a, Ctx, F> = Result<Mtbl<'a, Ctx, F>, <F as Factory<'a, Ct
/// Trait representing deserialisation rules for [Mentionable]s. /// Trait representing deserialisation rules for [Mentionable]s.
/// Crucial for [`crate::rstd::typeless`]. /// Crucial for [`crate::rstd::typeless`].
pub trait Factory<'a, Ctx: 'a + Context>: 'a + Send + Sync + Clone { pub trait Factory<'a, Ctx: Context<'a>>: 'a + Send + Sync + Clone {
/// Type of the associated objects. /// Type of the associated objects.
type Mtbl: Mentionable<'a, Ctx, Fctr = Self>; type Mtbl: Mentionable<'a, Ctx, Fctr = Self>;
/// Type of an error that [`Factory::deserialize`] can fail with. /// Type of an error that [`Factory::deserialize`] can fail with.
@ -105,7 +111,7 @@ pub type Mtbl<'a, Ctx, F> = <F as Factory<'a, Ctx>>::Mtbl;
pub type ParseError<'a, Ctx, F> = <F as Factory<'a, Ctx>>::ParseError; pub type ParseError<'a, Ctx, F> = <F as Factory<'a, Ctx>>::ParseError;
/// Extension trait for factories. /// Extension trait for factories.
pub trait ExtFactory<'a, Ctx: 'a + Context>: Factory<'a, Ctx> { pub trait ExtFactory<'a, Ctx: Context<'a>>: Factory<'a, Ctx> {
/// Parse the object from a slice. /// Parse the object from a slice.
fn parse_slice( fn parse_slice(
&self, &self,

View File

@ -21,7 +21,7 @@ impl Addresses {
} }
/// Read the next [Point]. /// Read the next [Point].
pub fn next_point<'a, 'b, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>( pub fn next_point<'a, 'b, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
&mut self, &mut self,
deserializer: &'b mut dyn Deserializer, deserializer: &'b mut dyn Deserializer,
resolver: Rc<dyn Resolver<'a, Ctx>>, resolver: Rc<dyn Resolver<'a, Ctx>>,
@ -40,7 +40,7 @@ impl Addresses {
} }
} }
fn _parse_slice<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>( fn _parse_slice<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
factory: &A::Fctr, factory: &A::Fctr,
slice: &[u8], slice: &[u8],
resolver: Rc<dyn Resolver<'a, Ctx>>, resolver: Rc<dyn Resolver<'a, Ctx>>,
@ -55,7 +55,7 @@ fn _parse_slice<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> ExtFactory<'a, Ctx> for F { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> ExtFactory<'a, Ctx> for F {
fn parse_slice( fn parse_slice(
&self, &self,
slice: &[u8], slice: &[u8],

View File

@ -1,7 +1,7 @@
use super::*; use super::*;
/// Represents a potentially resolvable [`Mentionable`]. /// Represents a potentially resolvable [`Mentionable`].
pub trait Origin<'a, Ctx: 'a + Context>: 'a { pub trait Origin<'a, Ctx: Context<'a>>: 'a {
/// Type of the associated object. /// Type of the associated object.
type Mtbl: Mentionable<'a, Ctx>; type Mtbl: Mentionable<'a, Ctx>;
/// Value of the associated factory. /// Value of the associated factory.

View File

@ -1,7 +1,7 @@
use super::*; use super::*;
/// The main way to represent a reference in ADN. /// The main way to represent a reference in ADN.
pub struct Point<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { pub struct Point<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
/// Hash of the referred content. /// Hash of the referred content.
/// Derived both from the serialised value ([`Serializable::serialize`]) /// Derived both from the serialised value ([`Serializable::serialize`])
/// and its topology ([`Mentionable::topology`]). /// and its topology ([`Mentionable::topology`]).
@ -10,7 +10,7 @@ pub struct Point<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub origin: Rc<dyn Origin<'a, Ctx, Mtbl = A>>, pub origin: Rc<dyn Origin<'a, Ctx, Mtbl = A>>,
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for Point<'a, Ctx, A> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
point: self.point, point: self.point,
@ -19,7 +19,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for Point<'a, Ctx, A>
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
/// See [`Origin::resolve`]. /// See [`Origin::resolve`].
pub fn resolve(&self) -> Resolution<'a, Ctx, A> { pub fn resolve(&self) -> Resolution<'a, Ctx, A> {
self.origin.clone().resolve() self.origin.clone().resolve()

View File

@ -1,10 +1,10 @@
use super::*; use super::*;
pub trait TakesPoints<'a, Ctx: 'a + Context> { pub trait TakesPoints<'a, Ctx: Context<'a>> {
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>); fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>);
} }
impl<'a, Ctx: 'a + Context> TakesPoints<'a, Ctx> for Vec<u8> { impl<'a, Ctx: Context<'a>> TakesPoints<'a, Ctx> for Vec<u8> {
/// The only natural implementation, as used in [`Mentionable::topology`]. /// The only natural implementation, as used in [`Mentionable::topology`].
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) { fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
self.extend(point.point) self.extend(point.point)

View File

@ -11,7 +11,7 @@ pub enum ResolutionError<L, P> {
/// See [`ResolutionResult`]. /// See [`ResolutionResult`].
pub type ResolutionFailure<'a, Ctx, A> = pub type ResolutionFailure<'a, Ctx, A> =
ResolutionError<<Ctx as Context>::LookupError<'a>, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>; ResolutionError<<Ctx as Context<'a>>::LookupError, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
/// Result yielded by [`Origin`]. /// Result yielded by [`Origin`].
pub type ResolutionResult<'a, Ctx, A> = Result<Rc<A>, ResolutionFailure<'a, Ctx, A>>; pub type ResolutionResult<'a, Ctx, A> = Result<Rc<A>, ResolutionFailure<'a, Ctx, A>>;
@ -20,7 +20,7 @@ pub type ResolutionResult<'a, Ctx, A> = Result<Rc<A>, ResolutionFailure<'a, Ctx,
pub type Resolution<'a, Ctx, A> = Wrapped<'a, Ctx, ResolutionResult<'a, Ctx, A>>; pub type Resolution<'a, Ctx, A> = Wrapped<'a, Ctx, ResolutionResult<'a, Ctx, A>>;
pub type HashResolutionResult<'a, Ctx> = pub type HashResolutionResult<'a, Ctx> =
Result<(Vec<u8>, Rc<dyn Resolver<'a, Ctx>>), <Ctx as Context>::LookupError<'a>>; Result<(Vec<u8>, Rc<dyn Resolver<'a, Ctx>>), <Ctx as Context<'a>>::LookupError>;
/// Shorthand for the type of values returned by [`Resolver::resolve`]. /// Shorthand for the type of values returned by [`Resolver::resolve`].
pub type HashResolution<'a, Ctx> = Wrapped<'a, Ctx, HashResolutionResult<'a, Ctx>>; pub type HashResolution<'a, Ctx> = Wrapped<'a, Ctx, HashResolutionResult<'a, Ctx>>;
@ -34,7 +34,7 @@ pub struct Address {
} }
/// Trait representing the "rainbow table" behaviour. /// Trait representing the "rainbow table" behaviour.
pub trait Resolver<'a, Ctx: 'a + Context>: 'a { pub trait Resolver<'a, Ctx: Context<'a>>: 'a {
/// Successfully returned value should be the inverse of the point passed /// Successfully returned value should be the inverse of the point passed
/// with topology header ([`Mentionable::topology()`]) omitted. /// with topology header ([`Mentionable::topology()`]) omitted.
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx>; fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx>;

View File

@ -1,6 +1,6 @@
use super::*; use super::*;
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
/// Make a [Point] from an [Address]. /// Make a [Point] from an [Address].
pub fn from_address( pub fn from_address(
address: Address, address: Address,
@ -18,13 +18,13 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
} }
} }
struct ResolverOrigin<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> { struct ResolverOrigin<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> {
r_factory: F, r_factory: F,
r_address: Address, r_address: Address,
r_resolver: Rc<dyn Resolver<'a, Ctx>>, r_resolver: Rc<dyn Resolver<'a, Ctx>>,
} }
fn _resolve_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>( fn _resolve_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
origin: Rc<ResolverOrigin<'a, Ctx, A::Fctr>>, origin: Rc<ResolverOrigin<'a, Ctx, A::Fctr>>,
) -> Resolution<'a, Ctx, A> { ) -> Resolution<'a, Ctx, A> {
let resolution = origin.r_resolver.clone().resolve(origin.r_address); let resolution = origin.r_resolver.clone().resolve(origin.r_address);
@ -41,7 +41,7 @@ fn _resolve_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
) )
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Origin<'a, Ctx> for ResolverOrigin<'a, Ctx, F> { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Origin<'a, Ctx> for ResolverOrigin<'a, Ctx, F> {
type Mtbl = F::Mtbl; type Mtbl = F::Mtbl;
fn factory(&self) -> OFctr<'a, Ctx, Self> { fn factory(&self) -> OFctr<'a, Ctx, Self> {

View File

@ -41,26 +41,18 @@ impl<S: Serializable> ExtSerializable for S {
/// ///
/// Until either Rust type system or [`crate::func`] take serious changes, /// Until either Rust type system or [`crate::func`] take serious changes,
/// this is the preferred way to switch between [Wrapped] and [fallible]. /// this is the preferred way to switch between [Wrapped] and [fallible].
pub trait FallibleContext: Context { pub trait FallibleContext<'a>: Context<'a> {
/// Convert a fallible wrapped into a wrapped result. /// Convert a fallible wrapped into a wrapped result.
fn unstuff<'a, A: 'a, E: 'a>( fn unstuff<A: 'a, E: 'a>(
wa: WrapE<'a, A, E, Self::Fallible>, wa: WrapE<'a, A, E, Self::Fallible>,
) -> Wrap<'a, Result<A, E>, Self::T> ) -> Wrap<'a, Result<A, E>, Self::T> {
where
Self: 'a,
{
Self::Fallible::unstuff(wa) Self::Fallible::unstuff(wa)
} }
/// Convert a wrapped result into a fallible wrapped. /// Convert a wrapped result into a fallible wrapped.
fn stuff<'a, A: 'a, E: 'a>( fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self::Fallible> {
fa: Wrap<'a, Result<A, E>, Self::T>,
) -> WrapE<'a, A, E, Self::Fallible>
where
Self: 'a,
{
Self::Fallible::stuff(fa) Self::Fallible::stuff(fa)
} }
} }
impl<Ctx: Context> FallibleContext for Ctx {} impl<'a, Ctx: Context<'a>> FallibleContext<'a> for Ctx {}

View File

@ -35,7 +35,7 @@ impl<A: Atomic> Serializable for AtomicObject<A> {
} }
} }
impl<'a, Ctx: 'a + Context, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A> { impl<'a, Ctx: Context<'a>, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A> {
type Fctr = AtomicFactory<A>; type Fctr = AtomicFactory<A>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -66,7 +66,7 @@ impl<A: Atomic> Clone for AtomicFactory<A> {
} }
} }
impl<'a, Ctx: 'a + Context, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> { impl<'a, Ctx: Context<'a>, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> {
type Mtbl = AtomicObject<A>; type Mtbl = AtomicObject<A>;
type ParseError = A::AParseError; type ParseError = A::AParseError;

View File

@ -9,7 +9,7 @@ use crate::rcore::*;
use super::{typeless::*, wrapped_origin::*, *}; use super::{typeless::*, wrapped_origin::*, *};
struct CastResolver<'a, Ctx: 'a + Context> { struct CastResolver<'a, Ctx: Context<'a>> {
points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>, points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>,
} }
@ -61,18 +61,18 @@ impl<'a> Display for CastError<'a> {
} }
impl<'a> CastError<'a> { impl<'a> CastError<'a> {
fn pure<Ctx: 'a + Context>(self) -> HashResolution<'a, Ctx> fn pure<Ctx: Context<'a>>(self) -> HashResolution<'a, Ctx>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
Ctx::T::pure(Err(self.into())) Ctx::T::pure(Err(self.into()))
} }
} }
impl<'a, Ctx: 'a + Context> CastResolver<'a, Ctx> { impl<'a, Ctx: Context<'a>> CastResolver<'a, Ctx> {
fn rc(points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) -> Rc<dyn Resolver<'a, Ctx>> fn rc(points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) -> Rc<dyn Resolver<'a, Ctx>>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
Rc::new(Self { points }) Rc::new(Self { points })
} }
@ -116,11 +116,11 @@ impl<'a, Ctx: 'a + Context> CastResolver<'a, Ctx> {
} }
} }
fn cast_resolved<'a, Ctx: 'a + Context>( fn cast_resolved<'a, Ctx: Context<'a>>(
resolved: ResolutionResult<'a, Ctx, TypelessMentionable<'a, Ctx>>, resolved: ResolutionResult<'a, Ctx, TypelessMentionable<'a, Ctx>>,
) -> HashResolutionResult<'a, Ctx> ) -> HashResolutionResult<'a, Ctx>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
match resolved { match resolved {
Ok(mentionable) => Ok(( Ok(mentionable) => Ok((
@ -134,9 +134,9 @@ where
} }
} }
impl<'a, Ctx: 'a + Context> Resolver<'a, Ctx> for CastResolver<'a, Ctx> impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for CastResolver<'a, Ctx>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> { fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> {
let point = match self.get_point(address) { let point = match self.get_point(address) {
@ -150,9 +150,9 @@ where
/// Returned by [`TypelessMentionable::cast`]. /// Returned by [`TypelessMentionable::cast`].
pub type CastResult<'a, Ctx, A> = Result<A, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>; pub type CastResult<'a, Ctx, A> = Result<A, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
impl<'a, Ctx: Context> TypelessMentionable<'a, Ctx> impl<'a, Ctx: Context<'a>> TypelessMentionable<'a, Ctx>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
pub fn cast_full<A: Mentionable<'a, Ctx>>( pub fn cast_full<A: Mentionable<'a, Ctx>>(
&self, &self,
@ -171,12 +171,12 @@ where
} }
} }
fn cast_resolve<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>( fn cast_resolve<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>, typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>,
factory: A::Fctr, factory: A::Fctr,
) -> Resolution<'a, Ctx, A> ) -> Resolution<'a, Ctx, A>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
Ctx::T::fmap( Ctx::T::fmap(
move |resolved| match resolved { move |resolved| match resolved {
@ -193,21 +193,21 @@ where
) )
} }
fn cast_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>( fn cast_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>, typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>,
factory: A::Fctr, factory: A::Fctr,
) -> Rc<dyn Origin<'a, Ctx, Mtbl = A>> ) -> Rc<dyn Origin<'a, Ctx, Mtbl = A>>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
wrapped_origin(factory.clone(), move || { wrapped_origin(factory.clone(), move || {
cast_resolve(typeless_origin.clone(), factory.clone()) cast_resolve(typeless_origin.clone(), factory.clone())
}) })
} }
impl<'a, Ctx: 'a + Context> Point<'a, Ctx, TypelessMentionable<'a, Ctx>> impl<'a, Ctx: Context<'a>> Point<'a, Ctx, TypelessMentionable<'a, Ctx>>
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
fn cast_origin<A: Mentionable<'a, Ctx>>( fn cast_origin<A: Mentionable<'a, Ctx>>(
&self, &self,

View File

@ -47,7 +47,7 @@ impl<ErrorA: Error, ErrorB: Error> Display for PairParseError<ErrorA, ErrorB> {
impl<ErrorA: Error, ErrorB: Error> Error for PairParseError<ErrorA, ErrorB> {} impl<ErrorA: Error, ErrorB: Error> Error for PairParseError<ErrorA, ErrorB> {}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx>
for Pair<A, B> for Pair<A, B>
where where
A::Fctr: InlineableFactory, A::Fctr: InlineableFactory,

View File

@ -51,18 +51,18 @@ impl<E: Display> Display for TreeParseError<E> {
impl<E: Error> Error for TreeParseError<E> {} impl<E: Error> Error for TreeParseError<E> {}
pub enum RBNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { pub enum RBNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
R(RNode<'a, Ctx, A>), R(RNode<'a, Ctx, A>),
B(BNode<'a, Ctx, A>), B(BNode<'a, Ctx, A>),
} }
pub struct BNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { pub struct BNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
cl: Nullable<'a, Ctx, RBNode<'a, Ctx, A>>, cl: Nullable<'a, Ctx, RBNode<'a, Ctx, A>>,
cr: Nullable<'a, Ctx, RBNode<'a, Ctx, A>>, cr: Nullable<'a, Ctx, RBNode<'a, Ctx, A>>,
key: Rc<A>, key: Rc<A>,
} }
pub struct RNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { pub struct RNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
cl: Nullable<'a, Ctx, BNode<'a, Ctx, A>>, cl: Nullable<'a, Ctx, BNode<'a, Ctx, A>>,
cr: Nullable<'a, Ctx, BNode<'a, Ctx, A>>, cr: Nullable<'a, Ctx, BNode<'a, Ctx, A>>,
key: Rc<A>, key: Rc<A>,
@ -83,7 +83,7 @@ pub struct RFactory<F> {
key_factory: F, key_factory: F,
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> RBNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> RBNode<'a, Ctx, A> {
fn key(&self) -> &A { fn key(&self) -> &A {
match self { match self {
RBNode::R(RNode { key, .. }) => key, RBNode::R(RNode { key, .. }) => key,
@ -92,7 +92,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> RBNode<'a, Ctx, A> {
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RBNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for RBNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) { fn serialize(&self, serializer: &mut dyn Serializer) {
match self { match self {
RBNode::R(r) => { RBNode::R(r) => {
@ -107,7 +107,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RBNode<'a,
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for BNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for BNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) { fn serialize(&self, serializer: &mut dyn Serializer) {
self.cl.serialize(serializer); self.cl.serialize(serializer);
self.cr.serialize(serializer); self.cr.serialize(serializer);
@ -115,7 +115,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for BNode<'a,
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for RNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) { fn serialize(&self, serializer: &mut dyn Serializer) {
self.cl.serialize(serializer); self.cl.serialize(serializer);
self.cr.serialize(serializer); self.cr.serialize(serializer);
@ -123,7 +123,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RNode<'a,
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RBNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RBNode<'a, Ctx, A> {
type Fctr = RBFactory<A::Fctr>; type Fctr = RBFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -140,7 +140,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RB
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BNode<'a, Ctx, A> {
type Fctr = BFactory<A::Fctr>; type Fctr = BFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -156,7 +156,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BN
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RNode<'a, Ctx, A> {
type Fctr = RFactory<A::Fctr>; type Fctr = RFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -172,7 +172,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RN
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<F> { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<F> {
type Mtbl = RBNode<'a, Ctx, F::Mtbl>; type Mtbl = RBNode<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>; type ParseError = TreeParseError<F::ParseError>;
@ -205,7 +205,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for BFactory<F> { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for BFactory<F> {
type Mtbl = BNode<'a, Ctx, F::Mtbl>; type Mtbl = BNode<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>; type ParseError = TreeParseError<F::ParseError>;
@ -234,7 +234,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for BFactory<F
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RFactory<F> { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RFactory<F> {
type Mtbl = RNode<'a, Ctx, F::Mtbl>; type Mtbl = RNode<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>; type ParseError = TreeParseError<F::ParseError>;

View File

@ -9,13 +9,13 @@ use super::*;
pub type TPE<'a, Ctx, A> = TreeParseError<ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>; pub type TPE<'a, Ctx, A> = TreeParseError<ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
pub type TreeFaiure<'a, Ctx, A> = pub type TreeFaiure<'a, Ctx, A> =
ResolutionError<<Ctx as Context>::LookupError<'a>, TPE<'a, Ctx, A>>; ResolutionError<<Ctx as Context<'a>>::LookupError, TPE<'a, Ctx, A>>;
pub type SubsetWrapped<'a, Ctx, A> = FallibleWrapped<'a, Ctx, bool, TreeFaiure<'a, Ctx, A>>; pub type SubsetWrapped<'a, Ctx, A> = FallibleWrapped<'a, Ctx, bool, TreeFaiure<'a, Ctx, A>>;
pub type SubsetMonad<'a, Ctx, A> = FallibleMonad<Ctx, TreeFaiure<'a, Ctx, A>>; pub type SubsetMonad<'a, Ctx, A> = FallibleMonad<'a, Ctx, TreeFaiure<'a, Ctx, A>>;
pub fn subset_pure<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>( pub fn subset_pure<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
value: bool, value: bool,
) -> SubsetWrapped<'a, Ctx, A> { ) -> SubsetWrapped<'a, Ctx, A> {
<SubsetMonad<'a, Ctx, A> as Pure>::pure(value) <SubsetMonad<'a, Ctx, A> as Pure>::pure(value)
@ -30,7 +30,7 @@ enum NodeType {
type RefData = (NodeType, Hash); type RefData = (NodeType, Hash);
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for BNode<'a, Ctx, A> TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for BNode<'a, Ctx, A>
{ {
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> { fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
@ -48,7 +48,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RNode<'a, Ctx, A> TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RNode<'a, Ctx, A>
{ {
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> { fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
@ -66,7 +66,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RBNode<'a, Ctx, A> TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RBNode<'a, Ctx, A>
{ {
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> { fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
@ -83,7 +83,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData> TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
for Point<'a, Ctx, BNode<'a, Ctx, A>> for Point<'a, Ctx, BNode<'a, Ctx, A>>
{ {
@ -105,7 +105,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData> TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
for Point<'a, Ctx, RNode<'a, Ctx, A>> for Point<'a, Ctx, RNode<'a, Ctx, A>>
{ {
@ -127,7 +127,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData> TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
for Point<'a, Ctx, RBNode<'a, Ctx, A>> for Point<'a, Ctx, RBNode<'a, Ctx, A>>
{ {
@ -149,13 +149,8 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
} }
} }
impl< impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, T: Mentionable<'a, Ctx>, D: 'a + PartialEq>
'a, TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, D> for Nullable<'a, Ctx, T>
Ctx: 'a + Context,
A: Mentionable<'a, Ctx>,
T: Mentionable<'a, Ctx>,
D: 'a + PartialEq,
> TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, D> for Nullable<'a, Ctx, T>
where where
Point<'a, Ctx, T>: TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, D>, Point<'a, Ctx, T>: TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, D>,
{ {

View File

@ -4,7 +4,7 @@ use crate::rcore::*;
use crate::rstd::{inlining::*, nullable::*, point::*, *}; use crate::rstd::{inlining::*, nullable::*, point::*, *};
/// Node containing a (nullable) reference to the next node and an element. /// Node containing a (nullable) reference to the next node and an element.
pub struct StackNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { pub struct StackNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
/// Reference comes first due to being inlineable. /// Reference comes first due to being inlineable.
pub rest: Stack<'a, Ctx, A>, pub rest: Stack<'a, Ctx, A>,
/// Unlike the original implementation in Python, doesn't default to using Point. /// Unlike the original implementation in Python, doesn't default to using Point.
@ -14,11 +14,11 @@ pub struct StackNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
/// Type representing a stack, an alias to a [Nullable] of a [StackNode]. /// Type representing a stack, an alias to a [Nullable] of a [StackNode].
pub type Stack<'a, Ctx, A> = Nullable<'a, Ctx, StackNode<'a, Ctx, A>>; pub type Stack<'a, Ctx, A> = Nullable<'a, Ctx, StackNode<'a, Ctx, A>>;
pub struct StackNodeFactory<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { pub struct StackNodeFactory<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
element_factory: A::Fctr, element_factory: A::Fctr,
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A> {
fn new(factory: A::Fctr) -> Self { fn new(factory: A::Fctr) -> Self {
StackNodeFactory { StackNodeFactory {
element_factory: factory, element_factory: factory,
@ -26,16 +26,14 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for StackNode<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for StackNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) { fn serialize(&self, serializer: &mut dyn Serializer) {
self.rest.serialize(serializer); self.rest.serialize(serializer);
self.element.serialize(serializer); self.element.serialize(serializer);
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for StackNode<'a, Ctx, A> {
for StackNode<'a, Ctx, A>
{
type Fctr = StackNodeFactory<'a, Ctx, A>; type Fctr = StackNodeFactory<'a, Ctx, A>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -48,7 +46,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx>
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for StackNodeFactory<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for StackNodeFactory<'a, Ctx, A> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
StackNodeFactory::new(self.element_factory.clone()) StackNodeFactory::new(self.element_factory.clone())
} }
@ -75,7 +73,7 @@ impl<ElementParseError: Error> Display for StackParseError<ElementParseError> {
impl<ElementParseError: Error> Error for StackParseError<ElementParseError> {} impl<ElementParseError: Error> Error for StackParseError<ElementParseError> {}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Factory<'a, Ctx> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Factory<'a, Ctx>
for StackNodeFactory<'a, Ctx, A> for StackNodeFactory<'a, Ctx, A>
{ {
type Mtbl = StackNode<'a, Ctx, A>; type Mtbl = StackNode<'a, Ctx, A>;
@ -127,7 +125,7 @@ pub type StackVecResult<'a, Ctx, A> = Result<Vec<Rc<A>>, StackFaiure<'a, Ctx, A>
pub type StackVecWrapped<'a, Ctx, A> = Wrapped<'a, Ctx, StackVecResult<'a, Ctx, A>>; pub type StackVecWrapped<'a, Ctx, A> = Wrapped<'a, Ctx, StackVecResult<'a, Ctx, A>>;
/// Extention trait with helper methods for [Stack]s. /// Extention trait with helper methods for [Stack]s.
pub trait ExtStack<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>: Mentionable<'a, Ctx> { pub trait ExtStack<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>: Mentionable<'a, Ctx> {
/// Get an empty stack ([`Nullable::Null`]). /// Get an empty stack ([`Nullable::Null`]).
fn empty(factory: A::Fctr) -> Self; fn empty(factory: A::Fctr) -> Self;
/// Get the corresponding factory. /// Get the corresponding factory.
@ -140,7 +138,7 @@ pub trait ExtStack<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>: Mentionable<
fn vec(self) -> StackVecWrapped<'a, Ctx, A>; fn vec(self) -> StackVecWrapped<'a, Ctx, A>;
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Stack<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Stack<'a, Ctx, A> {
fn empty(factory: A::Fctr) -> Self { fn empty(factory: A::Fctr) -> Self {
Nullable::Null(StackNodeFactory::new(factory.clone())) Nullable::Null(StackNodeFactory::new(factory.clone()))
} }
@ -176,14 +174,14 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for St
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> InlineableFactory impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableFactory
for StackNodeFactory<'a, Ctx, A> for StackNodeFactory<'a, Ctx, A>
where where
A::Fctr: InlineableFactory, A::Fctr: InlineableFactory,
{ {
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> FixedSizeFactory impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeFactory
for StackNodeFactory<'a, Ctx, A> for StackNodeFactory<'a, Ctx, A>
where where
A::Fctr: FixedSizeFactory, A::Fctr: FixedSizeFactory,
@ -193,7 +191,7 @@ where
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ConstSizeFactory impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeFactory
for StackNodeFactory<'a, Ctx, A> for StackNodeFactory<'a, Ctx, A>
where where
A::Fctr: ConstSizeFactory, A::Fctr: ConstSizeFactory,
@ -226,7 +224,7 @@ mod tests {
.collect()) .collect())
} }
fn make_stack<Ctx: 'static + Context>() -> T<Ctx> { fn make_stack<Ctx: Context<'static>>() -> T<Ctx> {
let stack: T<Ctx> = Stack::empty(Plain::f()); let stack: T<Ctx> = Stack::empty(Plain::f());
let stack: T<Ctx> = stack.add(Plain::from_slice(b"A0").into()); let stack: T<Ctx> = stack.add(Plain::from_slice(b"A0").into());

View File

@ -3,7 +3,7 @@
use super::*; use super::*;
/// Preferred monad for fallible uses. /// Preferred monad for fallible uses.
pub type FallibleMonad<Ctx, E> = <<Ctx as Context>::Fallible as MonadFailAny>::W<E>; pub type FallibleMonad<'a, Ctx, E> = <<Ctx as Context<'a>>::Fallible as MonadFailAny<'a>>::W<E>;
/// Preferred [Wrapped] [Result]. /// Preferred [Wrapped] [Result].
pub type FallibleWrapped<'a, Ctx, A, E> = Wrap<'a, A, FallibleMonad<Ctx, E>>; pub type FallibleWrapped<'a, Ctx, A, E> = Wrap<'a, A, FallibleMonad<'a, Ctx, E>>;

View File

@ -26,16 +26,16 @@ pub trait ConstSizeFactory: FixedSizeFactory {
} }
/// Object analogue of [`InlineableFactory`]. /// Object analogue of [`InlineableFactory`].
pub trait InlineableObject<'a, Ctx: 'a + Context>: 'a {} pub trait InlineableObject<'a, Ctx: Context<'a>>: 'a {}
/// Object analogue of [`FixedSizeFactory`]. /// Object analogue of [`FixedSizeFactory`].
pub trait FixedSizeObject<'a, Ctx: 'a + Context>: InlineableObject<'a, Ctx> { pub trait FixedSizeObject<'a, Ctx: Context<'a>>: InlineableObject<'a, Ctx> {
/// For [`ConstSizeObject`] this must return [`ConstSizeObject::SIZE`]. /// For [`ConstSizeObject`] this must return [`ConstSizeObject::SIZE`].
fn size(&self) -> usize; fn size(&self) -> usize;
} }
/// Object analogue of [`ConstSizeFactory`]. /// Object analogue of [`ConstSizeFactory`].
pub trait ConstSizeObject<'a, Ctx: 'a + Context>: FixedSizeObject<'a, Ctx> { pub trait ConstSizeObject<'a, Ctx: Context<'a>>: FixedSizeObject<'a, Ctx> {
/// Must be equal to [`FixedSizeObject::size()`]. /// Must be equal to [`FixedSizeObject::size()`].
const SIZE: usize; const SIZE: usize;
} }
@ -66,12 +66,12 @@ impl<A: ConstSizeAtomic> ConstSizeFactory for AtomicFactory<A> {
const SIZE: usize = A::SIZE; const SIZE: usize = A::SIZE;
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> InlineableObject<'a, Ctx> for A where impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableObject<'a, Ctx> for A where
A::Fctr: InlineableFactory A::Fctr: InlineableFactory
{ {
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> FixedSizeObject<'a, Ctx> for A impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeObject<'a, Ctx> for A
where where
A::Fctr: FixedSizeFactory, A::Fctr: FixedSizeFactory,
{ {
@ -80,7 +80,7 @@ where
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ConstSizeObject<'a, Ctx> for A impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeObject<'a, Ctx> for A
where where
A::Fctr: ConstSizeFactory, A::Fctr: ConstSizeFactory,
{ {
@ -134,7 +134,7 @@ pub type CheckedParseResult<'a, Ctx, F> =
Result<Mtbl<'a, Ctx, F>, CheckedParseError<ParseError<'a, Ctx, F>>>; Result<Mtbl<'a, Ctx, F>, CheckedParseError<ParseError<'a, Ctx, F>>>;
/// Extension trait for factories that ensures fixed size read. /// Extension trait for factories that ensures fixed size read.
pub trait CheckedParse<'a, Ctx: 'a + Context>: FixedSizeFactory + Factory<'a, Ctx> { pub trait CheckedParse<'a, Ctx: Context<'a>>: FixedSizeFactory + Factory<'a, Ctx> {
/// Verify proper read length using [`Deserializer::tell`]. /// Verify proper read length using [`Deserializer::tell`].
fn deserialize_checked( fn deserialize_checked(
&self, &self,
@ -145,12 +145,12 @@ pub trait CheckedParse<'a, Ctx: 'a + Context>: FixedSizeFactory + Factory<'a, Ct
} }
/// Extension trait for factories that ensures fixed size write. /// Extension trait for factories that ensures fixed size write.
pub trait CheckedSerialize<'a, Ctx: 'a + Context>: Serializable + FixedSizeObject<'a, Ctx> { pub trait CheckedSerialize<'a, Ctx: Context<'a>>: Serializable + FixedSizeObject<'a, Ctx> {
/// Verify proper write length using [`Serializer::tell`]. /// Verify proper write length using [`Serializer::tell`].
fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError>; fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError>;
} }
impl<'a, Ctx: 'a + Context, F: FixedSizeFactory + Factory<'a, Ctx>> CheckedParse<'a, Ctx> for F { impl<'a, Ctx: Context<'a>, F: FixedSizeFactory + Factory<'a, Ctx>> CheckedParse<'a, Ctx> for F {
fn deserialize_checked( fn deserialize_checked(
&self, &self,
deserializer: &mut dyn Deserializer, deserializer: &mut dyn Deserializer,
@ -173,7 +173,7 @@ impl<'a, Ctx: 'a + Context, F: FixedSizeFactory + Factory<'a, Ctx>> CheckedParse
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx> + FixedSizeObject<'a, Ctx>> impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + FixedSizeObject<'a, Ctx>>
CheckedSerialize<'a, Ctx> for A CheckedSerialize<'a, Ctx> for A
{ {
fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError> { fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError> {

View File

@ -27,7 +27,7 @@ pub trait StaticPairSerializable {
/// at the cost of having to specify two extra fields. /// at the cost of having to specify two extra fields.
/// ///
/// Note: [`StaticPair::FA`] requires [`InlineableFactory`] be implemented. /// Note: [`StaticPair::FA`] requires [`InlineableFactory`] be implemented.
pub trait StaticPair<'a, Ctx: 'a + Context>: pub trait StaticPair<'a, Ctx: Context<'a>>:
'a + StaticPairSerializable<SA = Self::A, SB = Self::B> 'a + StaticPairSerializable<SA = Self::A, SB = Self::B>
{ {
/// [Factory] data. May, depending on the usecase, include factory (factories) on the element(s). /// [Factory] data. May, depending on the usecase, include factory (factories) on the element(s).
@ -87,7 +87,7 @@ impl<SP> Deref for StaticPairObject<SP> {
} }
/// Generic implementation of a [Factory] for [StaticPair]s. /// Generic implementation of a [Factory] for [StaticPair]s.
pub struct StaticPairFactory<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> { pub struct StaticPairFactory<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> {
factory_data: SP::FactoryData, factory_data: SP::FactoryData,
} }
@ -99,7 +99,7 @@ impl<SP: StaticPairSerializable> Serializable for StaticPairObject<SP> {
} }
} }
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for StaticPairObject<SP> { impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for StaticPairObject<SP> {
type Fctr = StaticPairFactory<'a, Ctx, SP>; type Fctr = StaticPairFactory<'a, Ctx, SP>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -115,7 +115,7 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for St
} }
} }
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory<'a, Ctx, SP> { impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory<'a, Ctx, SP> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
factory_data: self.factory_data.clone(), factory_data: self.factory_data.clone(),
@ -123,7 +123,7 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory
} }
} }
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx> impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx>
for StaticPairFactory<'a, Ctx, SP> for StaticPairFactory<'a, Ctx, SP>
{ {
type Mtbl = StaticPairObject<SP>; type Mtbl = StaticPairObject<SP>;
@ -156,14 +156,14 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx>
} }
} }
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> InlineableFactory impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> InlineableFactory
for StaticPairFactory<'a, Ctx, SP> for StaticPairFactory<'a, Ctx, SP>
where where
SP::FB: InlineableFactory, SP::FB: InlineableFactory,
{ {
} }
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> FixedSizeFactory impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory
for StaticPairFactory<'a, Ctx, SP> for StaticPairFactory<'a, Ctx, SP>
where where
SP::FA: FixedSizeFactory, SP::FA: FixedSizeFactory,
@ -175,7 +175,7 @@ where
} }
} }
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> ConstSizeFactory impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ConstSizeFactory
for StaticPairFactory<'a, Ctx, SP> for StaticPairFactory<'a, Ctx, SP>
where where
SP::FA: ConstSizeFactory, SP::FA: ConstSizeFactory,

View File

@ -4,7 +4,7 @@ use crate::rcore::*;
use super::*; use super::*;
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> { fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {
let mut vec = mentioned.topology().to_vec(); let mut vec = mentioned.topology().to_vec();
mentioned.serialize(&mut vec); mentioned.serialize(&mut vec);
@ -29,7 +29,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
struct LocalOrigin<A>(Rc<A>); struct LocalOrigin<A>(Rc<A>);
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for LocalOrigin<A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for LocalOrigin<A> {
type Mtbl = A; type Mtbl = A;
fn factory(&self) -> A::Fctr { fn factory(&self) -> A::Fctr {
@ -47,13 +47,13 @@ impl<A> From<Rc<A>> for LocalOrigin<A> {
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<Rc<A>> for Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<Rc<A>> for Point<'a, Ctx, A> {
fn from(value: Rc<A>) -> Self { fn from(value: Rc<A>) -> Self {
Self::from_mentionable(value) Self::from_mentionable(value)
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<A> for Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<A> for Point<'a, Ctx, A> {
fn from(value: A) -> Self { fn from(value: A) -> Self {
Self::from_mentionable(value.into()) Self::from_mentionable(value.into())
} }

View File

@ -5,7 +5,7 @@ use crate::rcore::*;
use super::{inlining::*, point::*, *}; use super::{inlining::*, point::*, *};
/// Nullable reference type. Made for use as a linking element in data structures. /// Nullable reference type. Made for use as a linking element in data structures.
pub enum Nullable<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { pub enum Nullable<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
/// Unlike original Python implementation, stores the factory only in the null case. /// Unlike original Python implementation, stores the factory only in the null case.
Null(A::Fctr), Null(A::Fctr),
NotNull(Point<'a, Ctx, A>), NotNull(Point<'a, Ctx, A>),
@ -18,7 +18,7 @@ pub struct NullableFactory<F> {
factory: F, factory: F,
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for Nullable<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Nullable<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) { fn serialize(&self, serializer: &mut dyn Serializer) {
serializer.write(match self { serializer.write(match self {
Nullable::Null(_) => &HASH_ZEROS, Nullable::Null(_) => &HASH_ZEROS,
@ -27,7 +27,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for Nullable<'
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nullable<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nullable<'a, Ctx, A> {
type Fctr = NullableFactory<A::Fctr>; type Fctr = NullableFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -49,7 +49,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nu
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFactory<F> { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFactory<F> {
type Mtbl = Nullable<'a, Ctx, F::Mtbl>; type Mtbl = Nullable<'a, Ctx, F::Mtbl>;
type ParseError = PointParseError; type ParseError = PointParseError;
@ -74,7 +74,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFa
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<'a, Ctx, A>> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<'a, Ctx, A>> {
/// Reduce [Nullable] nesting. /// Reduce [Nullable] nesting.
pub fn join(&self) -> Resolution<'a, Ctx, Nullable<'a, Ctx, A>> { pub fn join(&self) -> Resolution<'a, Ctx, Nullable<'a, Ctx, A>> {
match self { match self {
@ -87,7 +87,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, A> {
fn from_mentionable(mentionable: Rc<A>) -> Self { fn from_mentionable(mentionable: Rc<A>) -> Self {
Self::NotNull(mentionable.into()) Self::NotNull(mentionable.into())
} }
@ -99,7 +99,7 @@ impl<F> NullableFactory<F> {
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for Nullable<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for Nullable<'a, Ctx, A> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
match self { match self {
Self::Null(factory) => Self::Null(factory.clone()), Self::Null(factory) => Self::Null(factory.clone()),
@ -112,13 +112,13 @@ impl<F> AlwaysConstSize for NullableFactory<F> {
const _SIZE: usize = HASH_SIZE; const _SIZE: usize = HASH_SIZE;
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<Rc<A>> for Nullable<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<Rc<A>> for Nullable<'a, Ctx, A> {
fn from(value: Rc<A>) -> Self { fn from(value: Rc<A>) -> Self {
Self::from_mentionable(value) Self::from_mentionable(value)
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<A> for Nullable<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<A> for Nullable<'a, Ctx, A> {
fn from(value: A) -> Self { fn from(value: A) -> Self {
Self::from_mentionable(value.into()) Self::from_mentionable(value.into())
} }

View File

@ -4,13 +4,13 @@ use std::{error::Error, fmt::Display, rc::Rc};
use crate::rcore::*; use crate::rcore::*;
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Point<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) { fn serialize(&self, serializer: &mut dyn Serializer) {
serializer.write(&self.point) serializer.write(&self.point)
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Point<'a, Ctx, A> {
type Fctr = PointFactory<A::Fctr>; type Fctr = PointFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -57,13 +57,13 @@ impl From<&[u8]> for PointParseError {
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> AsRef<[u8]> for Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> AsRef<[u8]> for Point<'a, Ctx, A> {
fn as_ref(&self) -> &[u8] { fn as_ref(&self) -> &[u8] {
&self.point &self.point
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for PointFactory<F> { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for PointFactory<F> {
type Mtbl = Point<'a, Ctx, F::Mtbl>; type Mtbl = Point<'a, Ctx, F::Mtbl>;
type ParseError = PointParseError; type ParseError = PointParseError;

View File

@ -86,16 +86,25 @@ impl<A> Traced<A> {
} }
} }
impl Diagnostic<TracedInstance> for TracedDiagnostic { impl<'a> Diagnostic<'a, TracedInstance> for TracedDiagnostic {
fn after<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> { fn after<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
where
'a: 'b,
{
fa.after(TraceBox::event(event())) fa.after(TraceBox::event(event()))
} }
fn before<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> { fn before<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
where
'a: 'b,
{
fa.before(TraceBox::event(event())) fa.before(TraceBox::event(event()))
} }
fn wrapped<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> { fn wrapped<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
where
'a: 'b,
{
fa.wrapped(event()) fa.wrapped(event())
} }
} }

View File

@ -2,17 +2,17 @@ use crate::rstd::{cast::*, typeless::*};
use super::*; use super::*;
struct TracedResolver<'a, Ctx: 'a + Context> { struct TracedResolver<'a, Ctx: Context<'a>> {
resolver: Rc<dyn Resolver<'a, Ctx>>, resolver: Rc<dyn Resolver<'a, Ctx>>,
} }
impl<'a, Ctx: 'a + Context<T = TracedInstance>> TracedResolver<'a, Ctx> { impl<'a, Ctx: Context<'a, 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 = TracedInstance>> Resolver<'a, Ctx> for TracedResolver<'a, Ctx> { impl<'a, Ctx: Context<'a, 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> {
TracedInstance::fmap( TracedInstance::fmap(
|resolved| { |resolved| {
@ -27,7 +27,7 @@ impl<'a, Ctx: 'a + Context<T = TracedInstance>> Resolver<'a, Ctx> for TracedReso
} }
/// Extension trait to trace the evaluation flow. /// Extension trait to trace the evaluation flow.
pub trait Traceable<'a, Ctx: 'a + Context<T = TracedInstance>>: pub trait Traceable<'a, Ctx: Context<'a, T = TracedInstance>>:
Mentionable<'a, Ctx> + Sized Mentionable<'a, Ctx> + Sized
{ {
/// Re-cast the value, adding an extra[^extra] /// Re-cast the value, adding an extra[^extra]
@ -38,9 +38,9 @@ pub trait Traceable<'a, Ctx: 'a + Context<T = TracedInstance>>:
fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self>; fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self>;
} }
impl<'a, Ctx: 'a + Context<T = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A impl<'a, Ctx: Context<'a, T = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A
where where
Ctx::LookupError<'a>: From<CastError<'a>>, Ctx::LookupError: From<CastError<'a>>,
{ {
fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self> { fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self> {
let factory = self.factory(); let factory = self.factory();

View File

@ -5,7 +5,7 @@ use super::{wrapped_origin::*, *};
type TypelessSerialize<'a> = dyn 'a + Fn(&mut dyn Serializer); type TypelessSerialize<'a> = dyn 'a + Fn(&mut dyn Serializer);
/// See [`Point::typeless`]. /// See [`Point::typeless`].
pub struct TypelessMentionable<'a, Ctx: 'a + Context> { pub struct TypelessMentionable<'a, Ctx: Context<'a>> {
t_serialize: Box<TypelessSerialize<'a>>, t_serialize: Box<TypelessSerialize<'a>>,
t_factory: TypelessFactory<'a, Ctx>, t_factory: TypelessFactory<'a, Ctx>,
t_topology: Hash, t_topology: Hash,
@ -14,7 +14,7 @@ pub struct TypelessMentionable<'a, Ctx: 'a + Context> {
type TypelessParsed<'a, Ctx> = Result<TypelessMentionable<'a, Ctx>, Box<dyn 'a + Error>>; type TypelessParsed<'a, Ctx> = Result<TypelessMentionable<'a, Ctx>, Box<dyn 'a + Error>>;
trait Tde<'a, Ctx: 'a + Context>: 'a + Send + Sync { trait Tde<'a, Ctx: Context<'a>>: 'a + Send + Sync {
fn clone_box(&self) -> TdeBox<'a, Ctx>; fn clone_box(&self) -> TdeBox<'a, Ctx>;
fn de( fn de(
@ -27,7 +27,7 @@ trait Tde<'a, Ctx: 'a + Context>: 'a + Send + Sync {
type TdeBox<'a, Ctx> = Box<dyn Tde<'a, Ctx>>; type TdeBox<'a, Ctx> = Box<dyn Tde<'a, Ctx>>;
trait Tut<'a, Ctx: 'a + Context>: 'a + Send + Sync { trait Tut<'a, Ctx: Context<'a>>: 'a + Send + Sync {
fn clone_box(&self) -> TutBox<'a, Ctx>; fn clone_box(&self) -> TutBox<'a, Ctx>;
fn ut(&self, tail: &[u8]) -> TypelessError<'a>; fn ut(&self, tail: &[u8]) -> TypelessError<'a>;
@ -36,18 +36,18 @@ trait Tut<'a, Ctx: 'a + Context>: 'a + Send + Sync {
type TutBox<'a, Ctx> = Box<dyn Tut<'a, Ctx>>; type TutBox<'a, Ctx> = Box<dyn Tut<'a, Ctx>>;
/// See [`Point::typeless`]/[`TypelessMentionable`]. /// See [`Point::typeless`]/[`TypelessMentionable`].
pub struct TypelessFactory<'a, Ctx: 'a + Context> { pub struct TypelessFactory<'a, Ctx: Context<'a>> {
t_deserialize: TdeBox<'a, Ctx>, t_deserialize: TdeBox<'a, Ctx>,
t_unexpected_tail: TutBox<'a, Ctx>, t_unexpected_tail: TutBox<'a, Ctx>,
} }
impl<'a, Ctx: 'a + Context> Serializable for TypelessMentionable<'a, Ctx> { impl<'a, Ctx: Context<'a>> Serializable for TypelessMentionable<'a, Ctx> {
fn serialize(&self, serializer: &mut dyn Serializer) { fn serialize(&self, serializer: &mut dyn Serializer) {
(self.t_serialize)(serializer); (self.t_serialize)(serializer);
} }
} }
impl<'a, Ctx: 'a + Context> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx> { impl<'a, Ctx: Context<'a>> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx> {
type Fctr = TypelessFactory<'a, Ctx>; type Fctr = TypelessFactory<'a, Ctx>;
fn factory(&self) -> Self::Fctr { fn factory(&self) -> Self::Fctr {
@ -65,7 +65,7 @@ impl<'a, Ctx: 'a + Context> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx
} }
} }
impl<'a, Ctx: 'a + Context> Clone for TypelessFactory<'a, Ctx> { impl<'a, Ctx: Context<'a>> Clone for TypelessFactory<'a, Ctx> {
fn clone(&self) -> Self { fn clone(&self) -> Self {
Self { Self {
t_deserialize: self.t_deserialize.clone_box(), t_deserialize: self.t_deserialize.clone_box(),
@ -86,7 +86,7 @@ impl<'a> Display for TypelessError<'a> {
impl<'a> Error for TypelessError<'a> {} impl<'a> Error for TypelessError<'a> {}
impl<'a, Ctx: 'a + Context> Factory<'a, Ctx> for TypelessFactory<'a, Ctx> { impl<'a, Ctx: Context<'a>> Factory<'a, Ctx> for TypelessFactory<'a, Ctx> {
type Mtbl = TypelessMentionable<'a, Ctx>; type Mtbl = TypelessMentionable<'a, Ctx>;
type ParseError = TypelessError<'a>; type ParseError = TypelessError<'a>;
@ -108,7 +108,7 @@ impl<'a, Ctx: 'a + Context> Factory<'a, Ctx> for TypelessFactory<'a, Ctx> {
} }
} }
impl<'a, Ctx: 'a + Context> TypelessMentionable<'a, Ctx> { impl<'a, Ctx: Context<'a>> TypelessMentionable<'a, Ctx> {
pub fn from_typed<A: Mentionable<'a, Ctx>>(mentionable: Rc<A>) -> Self { pub fn from_typed<A: Mentionable<'a, Ctx>>(mentionable: Rc<A>) -> Self {
let factory = TypelessFactory::from_typed(mentionable.factory()); let factory = TypelessFactory::from_typed(mentionable.factory());
let topology = mentionable.topology(); let topology = mentionable.topology();
@ -122,7 +122,7 @@ impl<'a, Ctx: 'a + Context> TypelessMentionable<'a, Ctx> {
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
fn clone_box(&self) -> TdeBox<'a, Ctx> { fn clone_box(&self) -> TdeBox<'a, Ctx> {
Box::new(self.clone()) Box::new(self.clone())
} }
@ -143,7 +143,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
} }
} }
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F { impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
fn clone_box(&self) -> TutBox<'a, Ctx> { fn clone_box(&self) -> TutBox<'a, Ctx> {
Box::new(self.clone()) Box::new(self.clone())
} }
@ -153,7 +153,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
} }
} }
impl<'a, Ctx: 'a + Context> TypelessFactory<'a, Ctx> { impl<'a, Ctx: Context<'a>> TypelessFactory<'a, Ctx> {
pub fn from_typed<F: Factory<'a, Ctx>>(factory: F) -> Self { pub fn from_typed<F: Factory<'a, Ctx>>(factory: F) -> Self {
TypelessFactory { TypelessFactory {
t_deserialize: Box::new(factory.clone()), t_deserialize: Box::new(factory.clone()),
@ -168,7 +168,7 @@ impl<'a> TypelessError<'a> {
} }
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
/// Typeless version of the point. /// Typeless version of the point.
pub fn typeless(&self) -> Point<'a, Ctx, TypelessMentionable<'a, Ctx>> { pub fn typeless(&self) -> Point<'a, Ctx, TypelessMentionable<'a, Ctx>> {
Point { Point {
@ -182,14 +182,14 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
} }
} }
pub trait MentionableExt<'a, Ctx: 'a + Context>: Mentionable<'a, Ctx> { pub trait MentionableExt<'a, Ctx: Context<'a>>: Mentionable<'a, Ctx> {
/// References ([Point]s) to other objects. Typeless. /// References ([Point]s) to other objects. Typeless.
fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>); fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>);
/// [Vec] of [Point]s as used by [`Mentionable::topology`]. /// [Vec] of [Point]s as used by [`Mentionable::topology`].
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>; fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>;
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A {
fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) { fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
self.points_typed(points) self.points_typed(points)
} }
@ -201,7 +201,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for
} }
} }
impl<'a, Ctx: 'a + Context> TakesPoints<'a, Ctx> impl<'a, Ctx: Context<'a>> TakesPoints<'a, Ctx>
for Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>> for Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>
{ {
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) { fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {

View File

@ -1,6 +1,6 @@
use super::*; use super::*;
pub fn wrapped_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>( pub fn wrapped_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
factory: A::Fctr, factory: A::Fctr,
resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>, resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>,
) -> Rc<dyn Origin<'a, Ctx, Mtbl = A>> { ) -> Rc<dyn Origin<'a, Ctx, Mtbl = A>> {
@ -10,7 +10,7 @@ pub fn wrapped_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
}) })
} }
pub trait MappableOrigin<'a, Ctx: 'a + Context>: Origin<'a, Ctx> { pub trait MappableOrigin<'a, Ctx: Context<'a>>: Origin<'a, Ctx> {
fn map<B: Mentionable<'a, Ctx>>( fn map<B: Mentionable<'a, Ctx>>(
self: Rc<Self>, self: Rc<Self>,
map_ok: impl 'a + Send + Sync + Clone + Fn(Rc<Self::Mtbl>) -> B, map_ok: impl 'a + Send + Sync + Clone + Fn(Rc<Self::Mtbl>) -> B,
@ -35,9 +35,9 @@ pub trait MappableOrigin<'a, Ctx: 'a + Context>: Origin<'a, Ctx> {
} }
} }
impl<'a, Ctx: 'a + Context, O: ?Sized + Origin<'a, Ctx>> MappableOrigin<'a, Ctx> for O {} impl<'a, Ctx: Context<'a>, O: ?Sized + Origin<'a, Ctx>> MappableOrigin<'a, Ctx> for O {}
fn map_resolve<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>>( fn map_resolve<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>>(
resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>, resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>,
map_ok: impl 'a + Fn(Rc<A>) -> B, map_ok: impl 'a + Fn(Rc<A>) -> B,
map_err: impl 'a + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>, map_err: impl 'a + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>,
@ -56,12 +56,12 @@ fn map_resolve<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>, B: Mentionable<'a
) )
} }
struct WrappedOrigin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { struct WrappedOrigin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
w_factory: A::Fctr, w_factory: A::Fctr,
w_resolve: Box<dyn 'a + Fn() -> Resolution<'a, Ctx, A>>, w_resolve: Box<dyn 'a + Fn() -> Resolution<'a, Ctx, A>>,
} }
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for WrappedOrigin<'a, Ctx, A> { impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for WrappedOrigin<'a, Ctx, A> {
type Mtbl = A; type Mtbl = A;
fn factory(&self) -> Fctr<'a, Ctx, Self::Mtbl> { fn factory(&self) -> Fctr<'a, Ctx, Self::Mtbl> {

View File

@ -12,16 +12,16 @@ use crate::rstd::typeless::*;
pub struct NoDiagnostic; pub struct NoDiagnostic;
impl<T: Monad> Diagnostic<T> for NoDiagnostic { impl<'a, T: Monad<'a>> Diagnostic<'a, T> for NoDiagnostic {
fn after<'a: 'b, 'b, A>(fa: T::F<'a, A>, _event: impl FnOnce() -> String) -> T::F<'a, A> { fn after<'b, A>(fa: T::F<'a, A>, _event: impl 'b + FnOnce() -> String) -> T::F<'a, A> {
fa fa
} }
fn before<'a: 'b, 'b, A>(fa: T::F<'a, A>, _event: impl FnOnce() -> String) -> T::F<'a, A> { fn before<'b, A>(fa: T::F<'a, A>, _event: impl 'b + FnOnce() -> String) -> T::F<'a, A> {
fa fa
} }
fn wrapped<'a: 'b, 'b, A>(fa: T::F<'a, A>, _event: impl FnOnce() -> String) -> T::F<'a, A> { fn wrapped<'b, A>(fa: T::F<'a, A>, _event: impl 'b + FnOnce() -> String) -> T::F<'a, A> {
fa fa
} }
} }
@ -66,14 +66,14 @@ impl<'a> Display for TestLookupError<'a> {
impl<'a> Error for TestLookupError<'a> {} impl<'a> Error for TestLookupError<'a> {}
impl Context for TestContextPlain { impl<'a> Context<'a> for TestContextPlain {
type T = instances::solo::SoloInstance; type T = instances::solo::SoloInstance;
type Fallible = instances::result::ResultFailAny; type Fallible = instances::result::ResultFailAny;
type D = NoDiagnostic; type D = NoDiagnostic;
type LookupError<'a> = TestLookupError<'a>; type LookupError = TestLookupError<'a>;
fn hash(s: &[u8]) -> Hash { fn hash(s: &[u8]) -> Hash {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();

View File

@ -8,14 +8,14 @@ use super::*;
pub struct TestContextCounted; pub struct TestContextCounted;
impl Context for TestContextCounted { impl<'a> Context<'a> for TestContextCounted {
type T = CountedInstance; type T = CountedInstance;
type Fallible = instances::result::ResultFailOver<Self::T>; type Fallible = instances::result::ResultFailOver<Self::T>;
type D = NoDiagnostic; type D = NoDiagnostic;
type LookupError<'a> = TestLookupError<'a>; type LookupError = TestLookupError<'a>;
fn hash(s: &[u8]) -> Hash { fn hash(s: &[u8]) -> Hash {
TestContextPlain::hash(s) TestContextPlain::hash(s)

View File

@ -5,14 +5,14 @@ use super::*;
pub struct TestContextTraced; pub struct TestContextTraced;
impl Context for TestContextTraced { impl<'a> Context<'a> for TestContextTraced {
type T = TracedInstance; type T = TracedInstance;
type Fallible = instances::result::ResultFailOver<Self::T>; type Fallible = instances::result::ResultFailOver<Self::T>;
type D = TracedDiagnostic; type D = TracedDiagnostic;
type LookupError<'a> = TestLookupError<'a>; type LookupError = TestLookupError<'a>;
fn hash(s: &[u8]) -> Hash { fn hash(s: &[u8]) -> Hash {
TestContextPlain::hash(s) TestContextPlain::hash(s)