Giter Club home page Giter Club logo

effing-mad's Introduction

Long story short, this library solves the function colouring problem and some other stuff that the Keyword Generics Initiative is looking at. It's an experiment in how an effect system could fit into Rust.

effing-mad, an effect library for Rust

This library brings algebraic effects and effect handlers to Rust, by providing traits and macros that allow writing effectful code in more or less the same style as Rust's existing async functions.

what does that mean

Effectful functions that use this library can explicitly suspend (yield) their execution and pass control back to their callers, who later resume the function. Data can be carried through both of these transitions, and this data is strongly typed in the same way as one would expect in Rust.

The data passed out of an effectful function specifies an action. It is given to an effect handler, which performs the action and passes the result back into the effectful function. Then, execution of the effectful function continues. It's like calling functions, but upside down.

As it turns out, calling functions upside down has some fantastic advantages. Since effects are handled inside the caller instead of the callee, there are no bounds on whether they are handled asynchronously, optionally, fallibly, or a bunch of other adverbs. On top of that, different callers can use different handlers on the same effectful function, meaning an effectful function that performs I/O can be called from either a regular fn or an async fn, and do the I/O in the "natural" way in both. No more distinction between popular_crate and popular_crate::blocking!*

* effing-mad not guaranteed to become popular. Use at own risk.

This whole mess can be seen in action in the examples/ directory. Check out the "basic" example first, unless you're really smart or brave or something.

why

TL;DR: API experimentation and fun

I saw a post about the recent efforts to make functions be usable from both async and sync contexts. The authors also wrote about the desire for higher-order functions such as Option::map to be able to be asynchronous, optional, fallible, or a bunch of other adjectives - without having to write a specialised function like try_async_map for each set of effects. This is the problem I was talking about last paragraph, where I also explain how an effect system could solve it.

Knowing this, I was surprised to see that in the FAQ of the post they answered "are you building an effect system?" with "not really". They never explained why not! So I did it instead, because I wanted to see what would happen.

how cool is it?

effing-mad is cool. Rad, even. Check out all these cool things it has:

  • unstable compiler features (coroutines, coroutine_trait)
  • a function with 22 type arguments
  • #![no_std]
  • scary category theory words (coproduct! ๐Ÿ‘ป)
  • procedural macros
  • declarative macros (used to have them, but I needed them to generate idents which they can't do :( )
  • unsafe
  • raw pointers
  • Pin, which means I'm really good at Rust
  • a dependency called "frunk". hehehehe

a market analysis conducted in 2022 determined that no other library has as many cool things as effing-mad, except maybe core. I mean, core invented Pin, which is cheating, so really I win.

some other facts

In pure functional languages like Haskell, side effects such as I/O are traditionally encoded in the language and its type system using monads. These are types which hold the effects and/or the result of the pure computation. So, if you want to have multiple types of effect, things get tricky because all your effect types want to hold the pure thing inside themselves, but you only have one pure thing going on. This means you have to use monad transformers. I don't really understand monad transformers, therefore they are bad.

On the other hand, I do understand algebraic effects, and therefore they are good. Also they compose far more easily and in my opinion are more intuitive. Download effing-mad today!

more facts - to do with rust this time

effing-mad uses coroutines. The implementation of it was made far easier by the lang team already needing functions that can be suspended and resumed, because that caused them to invent coroutines. Even though they were made for the compiler to be able to compile async fns, they're way more general than async fns are.

Coroutines are used by the compiler, but directly using them has not been stabilised yet because no one really needs it to be. That's why you need to use a nightly compiler to use effing-mad.

effing-mad's People

Contributors

jules-bertholet avatar jwong101 avatar max-heller avatar nadrieril avatar rosefromthedead avatar soooch avatar teohhanhui avatar wackbyte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

effing-mad's Issues

Cannot use more than 1 `EffectGroup` in `effectful` attribute macro?

#![feature(coroutines)]
#![feature(coroutine_trait)]

use std::borrow::Cow;

use effing_mad::{effectful, handle_group, handler};
use steamctl::cli_options::{options, Options};

effing_mad::effects! {
    Console<'a> {
        fn print(s: Cow<'a, str>) -> ();
    }
}

effing_mad::effects! {
    CliOptions {
        fn read() -> Options;
    }
}

fn main() {
    let console_handler = handler!(Console {
        print(s, _) => println!("{s}"),
    });
    let with_console = handle_group(do_command(), console_handler);
    let cli_options_handler = handler!(CliOptions {
        read() => options().run(),
    });
    let with_cli_options = handle_group(with_console, cli_options_handler);

    effing_mad::run(with_cli_options);
}

#[effectful(CliOptions, Console<'a>)]
fn do_command<'a>() {
    let options = yield CliOptions::read();
    yield Console::print(format!("{options:?}").into());
}

cargo clippy -- --verbose &> clippy.log:

clippy.log

    Checking steamctl v0.1.0 (/home/teohhanhui/Projects/teohhanhui/steamctl-rs)
error[E0277]: the trait bound `Console<'a>: effing_mad::Effect` is not satisfied
  --> src/bin/steamctl.rs:34:1
   |
34 | #[effectful(CliOptions, Console<'a>)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `effing_mad::Effect` is not implemented for `Console<'a>`, which is required by `effing_mad::frunk::Coproduct<Console<'a>, effing_mad::frunk::coproduct::CNil>: effing_mad::injection::EffectList`
   |
   = help: the following other types implement trait `effing_mad::Effect`:
             print<'a>
             effing_mad::effects::future::Await
             effing_mad::effects::future::GetContext
             read
   = note: required for `effing_mad::frunk::Coproduct<Console<'a>, effing_mad::frunk::coproduct::CNil>` to implement `effing_mad::injection::EffectList`

error[E0277]: the trait bound `effing_mad::frunk::coproduct::CNil: effing_mad::frunk::coproduct::CoprodUninjector<effing_mad::injection::Tagged<(), print<'_>>, _>` is not satisfied
  --> src/bin/steamctl.rs:34:1
   |
34 | #[effectful(CliOptions, Console<'a>)]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `effing_mad::frunk::coproduct::CoprodUninjector<effing_mad::injection::Tagged<(), print<'_>>, _>` is not implemented for `effing_mad::frunk::coproduct::CNil`, which is required by `effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>: effing_mad::frunk::coproduct::CoprodUninjector<effing_mad::injection::Tagged<(), print<'_>>, _>`
   |
   = help: the following other types implement trait `effing_mad::frunk::coproduct::CoprodUninjector<T, Idx>`:
             <effing_mad::frunk::Coproduct<Hd, Tl> as effing_mad::frunk::coproduct::CoprodUninjector<Hd, effing_mad::frunk::indices::Here>>
             <effing_mad::frunk::Coproduct<Hd, Tl> as effing_mad::frunk::coproduct::CoprodUninjector<T, effing_mad::frunk::indices::There<N>>>
   = note: required for `effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>` to implement `effing_mad::frunk::coproduct::CoprodUninjector<effing_mad::injection::Tagged<(), print<'_>>, effing_mad::frunk::indices::There<_>>`
   = note: 2 redundant requirements hidden
   = note: required for `effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>` to implement `effing_mad::frunk::coproduct::CoprodUninjector<effing_mad::injection::Tagged<(), print<'_>>, effing_mad::frunk::indices::There<effing_mad::frunk::indices::There<effing_mad::frunk::indices::There<_>>>>`
note: required by a bound in `effing_mad::macro_impl::get_inj`
  --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/macro_impl.rs:30:11
   |
27 | pub fn get_inj<E, Injs, Index>(injs: Injs, _marker: PhantomData<E>) -> Option<E::Injection>
   |        ------- required by a bound in this function
...
30 |     Injs: CoprodUninjector<Tagged<E::Injection, E>, Index>,
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `get_inj`
   = note: this error originates in the attribute macro `effectful` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `effing_mad::frunk::coproduct::CNil: effing_mad::frunk::coproduct::CoprodInjector<print<'_>, _>` is not satisfied
   --> src/bin/steamctl.rs:34:1
    |
34  | #[effectful(CliOptions, Console<'a>)]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `effing_mad::frunk::coproduct::CoprodInjector<print<'_>, _>` is not implemented for `effing_mad::frunk::coproduct::CNil`, which is required by `effing_mad::frunk::Coproduct<read, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>>: effing_mad::frunk::coproduct::CoprodInjector<print<'_>, _>`
    |
    = help: the following other types implement trait `effing_mad::frunk::coproduct::CoprodInjector<InjectType, Index>`:
              <effing_mad::frunk::Coproduct<Head, Tail> as effing_mad::frunk::coproduct::CoprodInjector<I, effing_mad::frunk::indices::There<TailIndex>>>
              <effing_mad::frunk::Coproduct<I, Tail> as effing_mad::frunk::coproduct::CoprodInjector<I, effing_mad::frunk::indices::Here>>
    = note: required for `effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>` to implement `effing_mad::frunk::coproduct::CoprodInjector<print<'_>, effing_mad::frunk::indices::There<_>>`
    = note: 1 redundant requirement hidden
    = note: required for `effing_mad::frunk::Coproduct<read, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>>` to implement `effing_mad::frunk::coproduct::CoprodInjector<print<'_>, effing_mad::frunk::indices::There<effing_mad::frunk::indices::There<_>>>`
note: required by a bound in `effing_mad::frunk::Coproduct::<Head, Tail>::inject`
   --> /home/teohhanhui/.cargo/registry/src/index.crates.io-6f17d22bba15001f/frunk_core-0.4.2/src/coproduct.rs:166:15
    |
164 |     pub fn inject<T, Index>(to_insert: T) -> Self
    |            ------ required by a bound in this associated function
165 |     where
166 |         Self: CoprodInjector<T, Index>,
    |               ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Coproduct::<Head, Tail>::inject`
    = note: this error originates in the attribute macro `effectful` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Console<'_>: effing_mad::Effect` is not satisfied
   --> src/bin/steamctl.rs:25:37
    |
25  |     let with_console = handle_group(do_command(), console_handler);
    |                        ------------ ^^^^^^^^^^^^ the trait `effing_mad::Effect` is not implemented for `Console<'_>`, which is required by `effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>: effing_mad::injection::EffectList`
    |                        |
    |                        required by a bound introduced by this call
    |
    = help: the following other types implement trait `effing_mad::Effect`:
              print<'a>
              effing_mad::effects::future::Await
              effing_mad::effects::future::GetContext
              read
    = note: required for `effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>` to implement `effing_mad::injection::EffectList`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:208:8
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
208 |     G: Coroutine<PreIs, Yield = PreEs, Return = R>,
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0277]: the trait bound `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield: effing_mad::injection::EffectList` is not satisfied
   --> src/bin/steamctl.rs:25:24
    |
25  |     let with_console = handle_group(do_command(), console_handler);
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `effing_mad::injection::EffectList` is not implemented for `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield`
    |
    = help: the following other types implement trait `effing_mad::injection::EffectList`:
              effing_mad::frunk::Coproduct<E, Es>
              effing_mad::frunk::coproduct::CNil
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:204:12
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
204 |     PreEs: EffectList<Injections = PreIs> + CoproductSubsetter<Es, EffsIndices, Remainder = PostEs>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:25:51
    |
22  |       let console_handler = handler!(Console {
    |  ___________________________-
23  | |         print(s, _) => println!("{s}"),
24  | |     });
    | |______- found signature defined here
25  |       let with_console = handle_group(do_command(), console_handler);
    |                          ------------               ^^^^^^^^^^^^^^^ expected due to this
    |                          |
    |                          required by a bound introduced by this call
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<print<'_>, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`
help: consider wrapping the function in a closure
    |
25  |     let with_console = handle_group(do_command(), |arg0: effing_mad::frunk::coproduct::CNil| console_handler(/* effing_mad::frunk::Coproduct<print<'_>, effing_mad::frunk::coproduct::CNil> */));
    |                                                   ++++++++++++++++++++++++++++++++++++++++++                +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:25:24
    |
22  |       let console_handler = handler!(Console {
    |  ___________________________-
23  | |         print(s, _) => println!("{s}"),
24  | |     });
    | |______- found signature defined here
25  |       let with_console = handle_group(do_command(), console_handler);
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected due to this
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<print<'_>, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0277]: the trait bound `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield: effing_mad::injection::EffectList` is not satisfied
   --> src/bin/steamctl.rs:29:28
    |
29  |     let with_cli_options = handle_group(with_console, cli_options_handler);
    |                            ^^^^^^^^^^^^ the trait `effing_mad::injection::EffectList` is not implemented for `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield`
    |
    = help: the following other types implement trait `effing_mad::injection::EffectList`:
              effing_mad::frunk::Coproduct<E, Es>
              effing_mad::frunk::coproduct::CNil
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:204:12
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
204 |     PreEs: EffectList<Injections = PreIs> + CoproductSubsetter<Es, EffsIndices, Remainder = PostEs>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0277]: the trait bound `Console<'_>: effing_mad::Effect` is not satisfied
   --> src/bin/steamctl.rs:29:28
    |
29  |     let with_cli_options = handle_group(with_console, cli_options_handler);
    |                            ^^^^^^^^^^^^ the trait `effing_mad::Effect` is not implemented for `Console<'_>`, which is required by `effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>: effing_mad::injection::EffectList`
    |
    = help: the following other types implement trait `effing_mad::Effect`:
              print<'a>
              effing_mad::effects::future::Await
              effing_mad::effects::future::GetContext
              read
    = note: required for `effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>` to implement `effing_mad::injection::EffectList`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:208:8
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
208 |     G: Coroutine<PreIs, Yield = PreEs, Return = R>,
    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:29:28
    |
22  |       let console_handler = handler!(Console {
    |  ___________________________-
23  | |         print(s, _) => println!("{s}"),
24  | |     });
    | |______- found signature defined here
...
29  |       let with_cli_options = handle_group(with_console, cli_options_handler);
    |                              ^^^^^^^^^^^^ expected due to this
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<print<'_>, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0277]: the trait bound `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield: effing_mad::injection::EffectList` is not satisfied
   --> src/bin/steamctl.rs:29:28
    |
29  |     let with_cli_options = handle_group(with_console, cli_options_handler);
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `effing_mad::injection::EffectList` is not implemented for `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield`
    |
    = help: the following other types implement trait `effing_mad::injection::EffectList`:
              effing_mad::frunk::Coproduct<E, Es>
              effing_mad::frunk::coproduct::CNil
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:204:12
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
204 |     PreEs: EffectList<Injections = PreIs> + CoproductSubsetter<Es, EffsIndices, Remainder = PostEs>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:29:55
    |
26  |       let cli_options_handler = handler!(CliOptions {
    |  _______________________________-
27  | |         read() => options().run(),
28  | |     });
    | |______- found signature defined here
29  |       let with_cli_options = handle_group(with_console, cli_options_handler);
    |                              ------------               ^^^^^^^^^^^^^^^^^^^ expected due to this
    |                              |
    |                              required by a bound introduced by this call
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<read, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`
help: consider wrapping the function in a closure
    |
29  |     let with_cli_options = handle_group(with_console, |arg0: effing_mad::frunk::coproduct::CNil| cli_options_handler(/* effing_mad::frunk::Coproduct<read, effing_mad::frunk::coproduct::CNil> */));
    |                                                       ++++++++++++++++++++++++++++++++++++++++++                    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:29:28
    |
26  |       let cli_options_handler = handler!(CliOptions {
    |  _______________________________-
27  | |         read() => options().run(),
28  | |     });
    | |______- found signature defined here
29  |       let with_cli_options = handle_group(with_console, cli_options_handler);
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected due to this
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<read, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:29:28
    |
22  |       let console_handler = handler!(Console {
    |  ___________________________-
23  | |         print(s, _) => println!("{s}"),
24  | |     });
    | |______- found signature defined here
...
29  |       let with_cli_options = handle_group(with_console, cli_options_handler);
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected due to this
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<print<'_>, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0271]: type mismatch resolving `<impl Coroutine<Coproduct<Begin, CNil>, Yield = <impl Coroutine<<<Coproduct<CliOptions, Coproduct<..., ...>> as FlattenEffects>::Out as EffectList>::Injections, Yield = ..., Return = ...> as Coroutine<...>>::Yield> as Coroutine<...>>::Yield == CNil`
  --> src/bin/steamctl.rs:31:21
   |
31 |     effing_mad::run(with_cli_options);
   |     --------------- ^^^^^^^^^^^^^^^^ expected `CNil`, found associated type
   |     |
   |     required by a bound introduced by this call
...
34 | #[effectful(CliOptions, Console<'a>)]
   | ------------------------------------- the found opaque type
   |
   = note:         expected enum `effing_mad::frunk::coproduct::CNil`
           found associated type `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield`
note: required by a bound in `effing_mad::run`
  --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:77:42
   |
75 | pub fn run<F, R>(mut f: F) -> R
   |        --- required by a bound in this function
76 | where
77 |     F: Coroutine<Coproduct<Begin, CNil>, Yield = CNil, Return = R>,
   |                                          ^^^^^^^^^^^^ required by this bound in `run`
help: consider constraining the associated type `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield` to `effing_mad::frunk::coproduct::CNil`
   |
34 | #[effectful(CliOptions, Console<'a>)]<Yield = effing_mad::frunk::coproduct::CNil>
   |                                      ++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the trait bound `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield: effing_mad::injection::EffectList` is not satisfied
   --> src/bin/steamctl.rs:31:5
    |
31  |     effing_mad::run(with_cli_options);
    |     ^^^^^^^^^^^^^^^ the trait `effing_mad::injection::EffectList` is not implemented for `<impl std::ops::Coroutine<<<effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out as effing_mad::injection::EffectList>::Injections, Yield = <effing_mad::frunk::Coproduct<CliOptions, effing_mad::frunk::Coproduct<Console<'_>, effing_mad::frunk::coproduct::CNil>> as effing_mad::macro_impl::FlattenEffects>::Out, Return = ()> as std::ops::Coroutine<effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<steamctl::cli_options::Options, read>, effing_mad::frunk::Coproduct<effing_mad::injection::Tagged<_, Console<'_>>, effing_mad::frunk::Coproduct<effing_mad::injection::Begin, effing_mad::frunk::coproduct::CNil>>>>>::Yield`
    |
    = help: the following other types implement trait `effing_mad::injection::EffectList`:
              effing_mad::frunk::Coproduct<E, Es>
              effing_mad::frunk::coproduct::CNil
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:204:12
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
204 |     PreEs: EffectList<Injections = PreIs> + CoproductSubsetter<Es, EffsIndices, Remainder = PostEs>,
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:31:5
    |
26  |       let cli_options_handler = handler!(CliOptions {
    |  _______________________________-
27  | |         read() => options().run(),
28  | |     });
    | |______- found signature defined here
...
31  |       effing_mad::run(with_cli_options);
    |       ^^^^^^^^^^^^^^^ expected due to this
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<read, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

error[E0631]: type mismatch in closure arguments
   --> src/bin/steamctl.rs:31:5
    |
22  |       let console_handler = handler!(Console {
    |  ___________________________-
23  | |         print(s, _) => println!("{s}"),
24  | |     });
    | |______- found signature defined here
...
31  |       effing_mad::run(with_cli_options);
    |       ^^^^^^^^^^^^^^^ expected due to this
    |
    = note: expected closure signature `fn(effing_mad::frunk::coproduct::CNil) -> _`
               found closure signature `fn(effing_mad::frunk::Coproduct<print<'_>, effing_mad::frunk::coproduct::CNil>) -> _`
note: required by a bound in `effing_mad::handle_group`
   --> /home/teohhanhui/.cargo/git/checkouts/effing-mad-e103e8f2d0b7efef/770c85e/src/lib.rs:199:36
    |
184 | pub fn handle_group<
    |        ------------ required by a bound in this function
...
199 |     mut handler: impl FnMut(Es) -> ControlFlow<R, Is>,
    |                                    ^^^^^^^^^^^^^^^^^^ required by this bound in `handle_group`

Some errors have detailed explanations: E0271, E0277, E0631.
For more information about an error, try `rustc --explain E0271`.
error: could not compile `steamctl` (bin "steamctl") due to 18 previous errors

Using 1 EffectGroup + 1 Effect works though...

Ergonomics of `effing_mad::run` and composition of effect handlers

Currently:

fn main() {
    let console_handler = handler!(Console {
        print(s, _) => println!("{s}"),
    });
    let with_console = handle_group(do_command(), console_handler);
    let cli_options_handler = handler!(CliOptions {
        read() => options().run(),
    });
    let with_cli_options = handle_group(with_console, cli_options_handler);

    effing_mad::run(with_cli_options);
}

What if:

fn main() {
    let console_handler = handler!(Console {
        print(s, _) => println!("{s}"),
    });
    let cli_options_handler = handler!(CliOptions {
        read() => options().run(),
    });

    effing_mad::run!(
        do_command()
        |> handle_group(console_handler)
        |> handle_group(cli_options_handler)
    );
}

And mainly because naming is hard... There is nothing special about with_cli_options in the previous code other than it just happens to be the last in the chain?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.