MonadContext
This commit is contained in:
parent
d990fb1431
commit
0954c86e92
@ -30,9 +30,7 @@ pub trait BinaryTrees: Clone {
|
||||
fn refer(&self, tree: &Self::Tree) -> Option<Self::Reference>;
|
||||
}
|
||||
|
||||
pub trait MonadTrees<'a>: FunctorContext<'a, T = Self::_Tm> + BinaryTrees {
|
||||
type _Tm: Monad<'a>;
|
||||
|
||||
pub trait MonadTrees<'a>: MonadContext<'a> + BinaryTrees {
|
||||
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node>;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,10 @@ impl<'a, BT: FunctorContext<'a>> FunctorContext<'a> for BalancedTrees<BT> {
|
||||
type T = BT::T;
|
||||
}
|
||||
|
||||
impl<'a, BT: MonadContext<'a>> MonadContext<'a> for BalancedTrees<BT> {
|
||||
type _Tm = Self::T;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum BalancingError {
|
||||
Height(HeightError),
|
||||
@ -109,8 +113,6 @@ impl<BT: TreesHeight> BinaryTrees 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> {
|
||||
let hp = *hp;
|
||||
let ctx = self.0.clone();
|
||||
|
@ -43,6 +43,10 @@ impl<'a, BT: FunctorContext<'a>> FunctorContext<'a> for BoundTrees<BT> {
|
||||
type T = BT::T;
|
||||
}
|
||||
|
||||
impl<'a, BT: MonadContext<'a>> MonadContext<'a> for BoundTrees<BT> {
|
||||
type _Tm = Self::T;
|
||||
}
|
||||
|
||||
pub trait BinaryTreesBindable<'a>: MonadTrees<'a> {
|
||||
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> {
|
||||
type _Tm = Self::T;
|
||||
|
||||
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node> {
|
||||
let ctx = self.0.clone();
|
||||
let bounds = reference.bounds.clone();
|
||||
|
@ -6,6 +6,10 @@ pub trait FunctorContext<'a>: 'a + Send {
|
||||
type T: WeakFunctor<'a>;
|
||||
}
|
||||
|
||||
pub trait MonadContext<'a>: FunctorContext<'a, T = Self::_Tm> {
|
||||
type _Tm: Monad<'a>;
|
||||
}
|
||||
|
||||
pub trait FunctorContextExt<'a>: FunctorContext<'a> {
|
||||
fn fmap<A: 'a + Send, B: 'a + Send>(
|
||||
fa: WrapC<'a, A, Self>,
|
||||
|
@ -86,6 +86,10 @@ impl<'a, A: 'a + Send> FunctorContext<'a> for Trees<A> {
|
||||
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> {
|
||||
type Node = Node<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> {
|
||||
type _Tm = Self::T;
|
||||
|
||||
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node> {
|
||||
reference.node.as_ref().clone()
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ mod resolver_origin;
|
||||
use std::{error::Error, sync::Arc};
|
||||
|
||||
use crate::func::context::*;
|
||||
use crate::func::*;
|
||||
use crate::mode::*;
|
||||
|
||||
pub use self::context::Context;
|
||||
@ -43,6 +42,8 @@ pub use self::resolution::{
|
||||
};
|
||||
|
||||
/// Helper alias for [`WeakFunctor::F`] of [`FunctorContext::T`].
|
||||
///
|
||||
/// [`WeakFunctor::F`]: crate::func::WeakFunctor::F
|
||||
pub type Wrapped<'a, Ctx, A> = WrapC<'a, A, Ctx>;
|
||||
|
||||
/// [Mentionable] base.
|
||||
|
@ -1,10 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
/// Execution context.
|
||||
pub trait Context<'a>: FallibleCtx<'a, T = Self::_Tm> + Send + Sync {
|
||||
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
|
||||
type _Tm: Monad<'a>;
|
||||
|
||||
pub trait Context<'a>: FallibleCtx<'a> + MonadContext<'a> + Send + Sync {
|
||||
/// See [`Diagnostic`].
|
||||
type D: Diagnostic<'a, Self::T>;
|
||||
|
||||
|
@ -69,6 +69,17 @@ impl<
|
||||
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<
|
||||
'a,
|
||||
Ctx: Context<'a>,
|
||||
@ -108,8 +119,6 @@ impl<
|
||||
E: 'a + Send,
|
||||
> MonadTrees<'a> for TreeContext2<'a, Ctx, A, C, E>
|
||||
{
|
||||
type _Tm = Self::T;
|
||||
|
||||
fn resolve(
|
||||
&self,
|
||||
reference: &Self::Reference,
|
||||
|
@ -72,9 +72,11 @@ impl<'a> FallibleCtx<'a> for TestContextPlain {
|
||||
type Fallible = instances::result::ResultFailAny;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextPlain {
|
||||
impl<'a> MonadContext<'a> for TestContextPlain {
|
||||
type _Tm = Self::T;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextPlain {
|
||||
type D = NoDiagnostic;
|
||||
|
||||
type LookupError = TestLookupError<'a>;
|
||||
|
@ -15,9 +15,11 @@ impl<'a> FallibleCtx<'a> for TestContextCounted {
|
||||
type Fallible = instances::result::ResultFailOver<Self::T>;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextCounted {
|
||||
impl<'a> MonadContext<'a> for TestContextCounted {
|
||||
type _Tm = Self::T;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextCounted {
|
||||
type D = NoDiagnostic;
|
||||
|
||||
type LookupError = TestLookupError<'a>;
|
||||
|
@ -14,9 +14,11 @@ impl<'a> FallibleCtx<'a> for TestContextTraced {
|
||||
type Fallible = instances::result::ResultFailOver<Self::T>;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextTraced {
|
||||
impl<'a> MonadContext<'a> for TestContextTraced {
|
||||
type _Tm = Self::T;
|
||||
}
|
||||
|
||||
impl<'a> Context<'a> for TestContextTraced {
|
||||
type D = TracedDiagnostic;
|
||||
|
||||
type LookupError = TestLookupError<'a>;
|
||||
|
Loading…
Reference in New Issue
Block a user