Giter VIP home page Giter VIP logo

Comments (3)

mitchellwrosen avatar mitchellwrosen commented on May 28, 2024

Ah, I just read in the readme the typeclass-based carriers are actually a feature, as they are what make fusion possible.

from fused-effects.

robrix avatar robrix commented on May 28, 2024

Ah, I just read in the readme the typeclass-based carriers are actually a feature, as they are what make fusion possible.

Yep, exactly!

That’s a neat use of reflection, but you can actually get this behaviour a little more prosaically by using a higher-order function as an argument to the carrier:

newtype TraceC m a = TraceC { runTraceC :: (String -> m ()) -> m a }

runTrace :: Carrier sig m => (String -> m ()) -> Eff (TraceC m) a -> m a
runTrace f = runTraceC f . interpret

(For a more involved example, see Control.Effect.Resumable; this is pretty much what runResumableWith/ResumableWithC is doing.)

This definitely reduces boilerplate! However, by using a higher-order function, you’re cheating yourself out of efficiency—the compiler is much less able/willing to fuse, inline, and optimize away the interpreter.

That’s essentially the tradeoff that fused-effects makes: a little more code to write a new effect handler, but extremely efficient execution once you have done so. As you found, and as demonstrated above, it can also express reduced-boilerplate implementations, but my personal feeling is that they don’t belong in this library.

On the other hand, for quick experiments, you could always try a carrier something like this:

newtype InterpreterC eff m a = InterpreterC { runInterpreterC :: (forall x . eff m (m x) -> m x) -> m a }

instance Carrier sig m => Carrier (eff :+: sig) (InterpreterC eff m) where
  

I’m not certain how to adapt the above to express carriers like StateC or ErrorC that wrap results in a functor, but it could probably be done.

from fused-effects.

robrix avatar robrix commented on May 28, 2024

I’m going to close this out now for tidiness, but thank you for sharing your use of reflection!

from fused-effects.

Related Issues (20)

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.