MonadContext
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-08-31 23:56:38 +00:00
parent d990fb1431
commit 0954c86e92
11 changed files with 40 additions and 19 deletions

View File

@ -30,9 +30,7 @@ pub trait BinaryTrees: Clone {
fn refer(&self, tree: &Self::Tree) -> Option<Self::Reference>; fn refer(&self, tree: &Self::Tree) -> Option<Self::Reference>;
} }
pub trait MonadTrees<'a>: FunctorContext<'a, T = Self::_Tm> + BinaryTrees { pub trait MonadTrees<'a>: MonadContext<'a> + BinaryTrees {
type _Tm: Monad<'a>;
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node>; fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node>;
} }

View File

@ -37,6 +37,10 @@ impl<'a, BT: FunctorContext<'a>> FunctorContext<'a> for BalancedTrees<BT> {
type T = BT::T; type T = BT::T;
} }
impl<'a, BT: MonadContext<'a>> MonadContext<'a> for BalancedTrees<BT> {
type _Tm = Self::T;
}
#[derive(Debug)] #[derive(Debug)]
pub enum BalancingError { pub enum BalancingError {
Height(HeightError), Height(HeightError),
@ -109,8 +113,6 @@ impl<BT: TreesHeight> BinaryTrees for BalancedTrees<BT> {
} }
impl<'a, BT: BinaryTreesUnbalanced<'a>> MonadTrees<'a> for BalancedTrees<BT> { impl<'a, BT: BinaryTreesUnbalanced<'a>> MonadTrees<'a> for BalancedTrees<BT> {
type _Tm = Self::T;
fn resolve(&self, (reference, hp): &Self::Reference) -> BTWrap<'a, Self, Self::Node> { fn resolve(&self, (reference, hp): &Self::Reference) -> BTWrap<'a, Self, Self::Node> {
let hp = *hp; let hp = *hp;
let ctx = self.0.clone(); let ctx = self.0.clone();

View File

@ -43,6 +43,10 @@ impl<'a, BT: FunctorContext<'a>> FunctorContext<'a> for BoundTrees<BT> {
type T = BT::T; type T = BT::T;
} }
impl<'a, BT: MonadContext<'a>> MonadContext<'a> for BoundTrees<BT> {
type _Tm = Self::T;
}
pub trait BinaryTreesBindable<'a>: MonadTrees<'a> { pub trait BinaryTreesBindable<'a>: MonadTrees<'a> {
fn bounds_error<T: 'a + Send>(&self, error: BoundsError<Self::Key>) -> BTWrap<'a, Self, T>; fn bounds_error<T: 'a + Send>(&self, error: BoundsError<Self::Key>) -> BTWrap<'a, Self, T>;
@ -98,8 +102,6 @@ impl<BT: BinaryTrees> BinaryTrees for BoundTrees<BT> {
} }
impl<'a, BT: BinaryTreesBindable<'a>> MonadTrees<'a> for BoundTrees<BT> { impl<'a, BT: BinaryTreesBindable<'a>> MonadTrees<'a> for BoundTrees<BT> {
type _Tm = Self::T;
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node> { fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node> {
let ctx = self.0.clone(); let ctx = self.0.clone();
let bounds = reference.bounds.clone(); let bounds = reference.bounds.clone();

View File

@ -6,6 +6,10 @@ pub trait FunctorContext<'a>: 'a + Send {
type T: WeakFunctor<'a>; type T: WeakFunctor<'a>;
} }
pub trait MonadContext<'a>: FunctorContext<'a, T = Self::_Tm> {
type _Tm: Monad<'a>;
}
pub trait FunctorContextExt<'a>: FunctorContext<'a> { pub trait FunctorContextExt<'a>: FunctorContext<'a> {
fn fmap<A: 'a + Send, B: 'a + Send>( fn fmap<A: 'a + Send, B: 'a + Send>(
fa: WrapC<'a, A, Self>, fa: WrapC<'a, A, Self>,

View File

@ -86,6 +86,10 @@ impl<'a, A: 'a + Send> FunctorContext<'a> for Trees<A> {
type T = instances::solo::SoloInstance; type T = instances::solo::SoloInstance;
} }
impl<'a, A: 'a + Send> MonadContext<'a> for Trees<A> {
type _Tm = Self::T;
}
impl<A: Send + Sync + Ord + Clone> BinaryTrees for Trees<A> { impl<A: Send + Sync + Ord + Clone> BinaryTrees for Trees<A> {
type Node = Node<A>; type Node = Node<A>;
type Reference = Reference<A>; type Reference = Reference<A>;
@ -111,8 +115,6 @@ impl<A: Send + Sync + Ord + Clone> BinaryTrees for Trees<A> {
} }
impl<'a, A: 'a + Send + Sync + Ord + Clone> MonadTrees<'a> for Trees<A> { impl<'a, A: 'a + Send + Sync + Ord + Clone> MonadTrees<'a> for Trees<A> {
type _Tm = Self::T;
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node> { fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node> {
reference.node.as_ref().clone() reference.node.as_ref().clone()
} }

View File

@ -21,7 +21,6 @@ mod resolver_origin;
use std::{error::Error, sync::Arc}; use std::{error::Error, sync::Arc};
use crate::func::context::*; use crate::func::context::*;
use crate::func::*;
use crate::mode::*; use crate::mode::*;
pub use self::context::Context; pub use self::context::Context;
@ -43,6 +42,8 @@ pub use self::resolution::{
}; };
/// Helper alias for [`WeakFunctor::F`] of [`FunctorContext::T`]. /// Helper alias for [`WeakFunctor::F`] of [`FunctorContext::T`].
///
/// [`WeakFunctor::F`]: crate::func::WeakFunctor::F
pub type Wrapped<'a, Ctx, A> = WrapC<'a, A, Ctx>; pub type Wrapped<'a, Ctx, A> = WrapC<'a, A, Ctx>;
/// [Mentionable] base. /// [Mentionable] base.

View File

@ -1,10 +1,7 @@
use super::*; use super::*;
/// Execution context. /// Execution context.
pub trait Context<'a>: FallibleCtx<'a, T = Self::_Tm> + Send + Sync { pub trait Context<'a>: FallibleCtx<'a> + MonadContext<'a> + Send + Sync {
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
type _Tm: Monad<'a>;
/// See [`Diagnostic`]. /// See [`Diagnostic`].
type D: Diagnostic<'a, Self::T>; type D: Diagnostic<'a, Self::T>;

View File

@ -69,6 +69,17 @@ impl<
type T = FallibleMonad<'a, Ctx, TreeContextError<'a, Ctx, A, E>>; type T = FallibleMonad<'a, Ctx, TreeContextError<'a, Ctx, A, E>>;
} }
impl<
'a,
Ctx: Context<'a>,
A: Mentionable<'a, Ctx> + Clone,
C: 'a + Comparator<A>,
E: 'a + Send,
> MonadContext<'a> for TreeContext2<'a, Ctx, A, C, E>
{
type _Tm = Self::T;
}
impl< impl<
'a, 'a,
Ctx: Context<'a>, Ctx: Context<'a>,
@ -108,8 +119,6 @@ impl<
E: 'a + Send, E: 'a + Send,
> MonadTrees<'a> for TreeContext2<'a, Ctx, A, C, E> > MonadTrees<'a> for TreeContext2<'a, Ctx, A, C, E>
{ {
type _Tm = Self::T;
fn resolve( fn resolve(
&self, &self,
reference: &Self::Reference, reference: &Self::Reference,

View File

@ -72,9 +72,11 @@ impl<'a> FallibleCtx<'a> for TestContextPlain {
type Fallible = instances::result::ResultFailAny; type Fallible = instances::result::ResultFailAny;
} }
impl<'a> Context<'a> for TestContextPlain { impl<'a> MonadContext<'a> for TestContextPlain {
type _Tm = Self::T; type _Tm = Self::T;
}
impl<'a> Context<'a> for TestContextPlain {
type D = NoDiagnostic; type D = NoDiagnostic;
type LookupError = TestLookupError<'a>; type LookupError = TestLookupError<'a>;

View File

@ -15,9 +15,11 @@ impl<'a> FallibleCtx<'a> for TestContextCounted {
type Fallible = instances::result::ResultFailOver<Self::T>; type Fallible = instances::result::ResultFailOver<Self::T>;
} }
impl<'a> Context<'a> for TestContextCounted { impl<'a> MonadContext<'a> for TestContextCounted {
type _Tm = Self::T; type _Tm = Self::T;
}
impl<'a> Context<'a> for TestContextCounted {
type D = NoDiagnostic; type D = NoDiagnostic;
type LookupError = TestLookupError<'a>; type LookupError = TestLookupError<'a>;

View File

@ -14,9 +14,11 @@ impl<'a> FallibleCtx<'a> for TestContextTraced {
type Fallible = instances::result::ResultFailOver<Self::T>; type Fallible = instances::result::ResultFailOver<Self::T>;
} }
impl<'a> Context<'a> for TestContextTraced { impl<'a> MonadContext<'a> for TestContextTraced {
type _Tm = Self::T; type _Tm = Self::T;
}
impl<'a> Context<'a> for TestContextTraced {
type D = TracedDiagnostic; type D = TracedDiagnostic;
type LookupError = TestLookupError<'a>; type LookupError = TestLookupError<'a>;