MonadFailAny + MonadFailOver + Context::Fallible
This commit is contained in:
parent
5c9e4985b6
commit
6a19cdaf81
@ -32,6 +32,8 @@ pub trait Context {
|
||||
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
|
||||
type T: Monad;
|
||||
|
||||
type Fallible: MonadFailOver<Self::T>;
|
||||
|
||||
type D: Diagnostic<Self::T>;
|
||||
|
||||
/// Type to represent resolution errors mainly arising in [`Resolver::resolve`].
|
||||
|
20
src/func.rs
20
src/func.rs
@ -232,3 +232,23 @@ pub trait LocalFunctor: WeakFunctor {
|
||||
where
|
||||
Self: 'a;
|
||||
}
|
||||
|
||||
pub trait MonadFailAny {
|
||||
type W<E>: MonadFail<E>;
|
||||
}
|
||||
|
||||
pub trait MonadFailOver<T: Monad>: MonadFailAny {
|
||||
fn unstuff<'a, A: 'a, E: 'a>(
|
||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||
) -> <T as WeakFunctor>::F<'a, Result<A, E>>
|
||||
where
|
||||
Self: 'a,
|
||||
T: 'a;
|
||||
|
||||
fn stuff<'a, A: 'a, E: 'a>(
|
||||
fa: <T as WeakFunctor>::F<'a, Result<A, E>>,
|
||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
||||
where
|
||||
Self: 'a,
|
||||
T: 'a;
|
||||
}
|
||||
|
@ -121,6 +121,14 @@ impl<U: Monad, V: Monad + LocalFunctor> Monad for CompositionClass<U, V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, U: Monad, V: MonadFail<E> + LocalFunctor> MonadFail<E> for CompositionClass<U, V> {
|
||||
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
|
||||
where
|
||||
Self: 'a {
|
||||
U::pure(V::fail(e))
|
||||
}
|
||||
}
|
||||
|
||||
impl<U: LocalFunctor + Functor, V: LocalFunctor> LocalFunctor for CompositionClass<U, V> {
|
||||
fn unstuff<'a, A: 'a, B: 'a>(state: Self::F<'a, IState<A, B>>) -> IState<A, Self::F<'a, B>>
|
||||
where
|
||||
|
@ -157,3 +157,59 @@ impl<E> MonadFail<E> for ResultClass<E> {
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ResultFailAny;
|
||||
|
||||
impl MonadFailAny for ResultFailAny {
|
||||
type W<E> = ResultClass<E>;
|
||||
}
|
||||
|
||||
impl MonadFailOver<classes::solo::SoloClass> for ResultFailAny {
|
||||
fn unstuff<'a, A: 'a, E: 'a>(
|
||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||
) -> <classes::solo::SoloClass as WeakFunctor>::F<'a, Result<A, E>>
|
||||
where
|
||||
Self: 'a,
|
||||
classes::solo::SoloClass: 'a,
|
||||
{
|
||||
wa
|
||||
}
|
||||
|
||||
fn stuff<'a, A: 'a, E: 'a>(
|
||||
fa: <classes::solo::SoloClass as WeakFunctor>::F<'a, Result<A, E>>,
|
||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
||||
where
|
||||
Self: 'a,
|
||||
classes::solo::SoloClass: 'a,
|
||||
{
|
||||
fa
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ResultFailOver<T: Monad>(T);
|
||||
|
||||
impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
||||
type W<E> = super::composition::CompositionClass<T, ResultClass<E>>;
|
||||
}
|
||||
|
||||
impl<T: Monad> MonadFailOver<T> for ResultFailOver<T> {
|
||||
fn unstuff<'a, A: 'a, E: 'a>(
|
||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||
) -> <T as WeakFunctor>::F<'a, Result<A, E>>
|
||||
where
|
||||
Self: 'a,
|
||||
T: 'a,
|
||||
{
|
||||
wa
|
||||
}
|
||||
|
||||
fn stuff<'a, A: 'a, E: 'a>(
|
||||
fa: <T as WeakFunctor>::F<'a, Result<A, E>>,
|
||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
||||
where
|
||||
Self: 'a,
|
||||
T: 'a,
|
||||
{
|
||||
fa
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,8 @@ impl<'a> Error for TestLookupError<'a> {}
|
||||
impl Context for TestContextPlain {
|
||||
type T = classes::solo::SoloClass;
|
||||
|
||||
type Fallible = classes::result::ResultFailAny;
|
||||
|
||||
type D = NoDiagnostic;
|
||||
|
||||
type LookupError<'a> = TestLookupError<'a>;
|
||||
|
@ -10,6 +10,8 @@ pub struct TestContextCounted;
|
||||
impl Context for TestContextCounted {
|
||||
type T = CountedClass;
|
||||
|
||||
type Fallible = classes::result::ResultFailOver<Self::T>;
|
||||
|
||||
type D = NoDiagnostic;
|
||||
|
||||
type LookupError<'a> = TestLookupError<'a>;
|
||||
|
@ -8,6 +8,8 @@ pub struct TestContextTraced;
|
||||
impl Context for TestContextTraced {
|
||||
type T = TracedClass;
|
||||
|
||||
type Fallible = classes::result::ResultFailOver<Self::T>;
|
||||
|
||||
type D = TracedDiagnostic;
|
||||
|
||||
type LookupError<'a> = TestLookupError<'a>;
|
||||
|
Loading…
Reference in New Issue
Block a user