Comments (3)
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.
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.
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)
- Unversioned documentation links all point to master HOT 3
- throwError law is undocumented
- Add Accum effect HOT 4
- Regression with Error in fused effects 1.1 HOT 7
- Carriers should preserve MonadResource HOT 3
- fused-effects 1.1 performance degradation? HOT 6
- TraceText Effect HOT 3
- MonadBaseControl for Labelled Effects HOT 1
- Add instances of MonadCatch, MonadThrow, MonadMask, where possible? HOT 6
- Indexed error handling HOT 1
- This code for solving prime numbers is about 6 times slower than primes HOT 2
- test suite build failure on Stackage Nightly (GHC 9.0.1) HOT 2
- Why are we slower than mtl? HOT 7
- Difficulty (impossibility?) to wrap `reactive-banana` as effect HOT 2
- Export effect constructors from separate modules
- GHC 9.4.1 compatibility
- Write infodump on how to define algebras
- Accum effect mixed with other effects duplicates accumulated monoidal value HOT 4
- The README makes an unclear statement about visible type applications relating to running effects HOT 1
- Update dependency bounds to support GHC 9.8 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fused-effects.