Comments (10)
What features of bracket do you need? If you just need the basic acquire, perform, release, then it should be straightforward monadically. If you need the exception-handling features, then that would involve another effect.
from extensible-effects.
yes, i wanted the exception handling part. how can that be implemented in extensible-effects? my short tinkering did not yield any results. i don't know how to construct something like liftControlIO :: SetMember Lift (Lift IO) => (Eff r a -> IO a) -> Eff r a
which would, i guess, let me implement all the bracket's and mask's i'd like.
can you kindly point me in the right direction?
edit: playing around with it, that does not make any sense. i'll have to capture the monadic state and restore it. i don't feel qualified to adapt monad-control
to extensible-effects...
from extensible-effects.
This is as far as I got before giving up:
bracket :: (Monad m, Typeable1 m, SetMember Lift (Lift m) r, Typeable e, Member (Exc e) r)
=> Eff r a
-> (a -> Eff r b)
-> (a -> Eff r c)
-> Eff r c
bracket acquire act release = do
a <- acquire
e <- catchExc (Nothing <$ act a) (return . Just)
c <- release a
() <- maybe (return ()) throwExc e
return c
The remaining compiler error is:
src/Control/Eff/Exception.hs:116:10:
Could not deduce (Member (* -> *) * (Exc a0) r)
arising from a use of `catchExc'
from the context (Monad m,
Typeable1 m,
SetMember ((* -> *) -> * -> *) * Lift (Lift m) r,
Typeable e,
Member (* -> *) * (Exc e) r)
bound by the type signature for
bracket :: (Monad m, Typeable1 m,
SetMember ((* -> *) -> * -> *) * Lift (Lift m) r, Typeable e,
Member (* -> *) * (Exc e) r) =>
Eff r a -> (a -> Eff r b) -> (a -> Eff r c) -> Eff r c
at src/Control/Eff/Exception.hs:(109,12)-(113,18)
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance [overlap ok] Member (* -> *) * t ((:>) k t r)
-- Defined in `Data.OpenUnion1'
instance [overlap ok] Member k k1 t r =>
Member k * t ((:>) k1 t' r)
-- Defined in `Data.OpenUnion1'
Possible fix:
add an instance declaration for (Member (* -> *) * (Exc a0) r)
In a stmt of a 'do' block:
e <- catchExc (Nothing <$ act a) (return . Just)
In the expression:
do { a <- acquire;
e <- catchExc (Nothing <$ act a) (return . Just);
c <- release a;
() <- maybe (return ()) throwExc e;
.... }
In an equation for `bracket':
bracket acquire act release
= do { a <- acquire;
e <- catchExc (Nothing <$ act a) (return . Just);
c <- release a;
.... }
The type of exception is ambiguous, because the type signature doesn't specify it in any way. Looking into the definition of bracket
and onException
in Control.Exception.Base
, I'm still a little confused on how they manage this. I'll think more on this later; it seems like we'll need to do an implementation of something like onException
using extensible-effects internals.
from extensible-effects.
thank you for looking into it.
I know that's not the main problem, but you ordered release and act wrong. it's the other way around.
i'm also not sure, that function will do what i want. i will need a way to catch native io exceptions. for that i guess a way to run a -> Eff r a
within an IO
context would be needed. i played around extending Lift
but that did not work out so far.
Sorry for the incomplete comment earlier, i was on my phone...
from extensible-effects.
@ibotty any updates on this?
from extensible-effects.
unfortunately not. i won't have time this year for it either. sorry.
btw: thanks for giving momentum to extensible-effects
.
from extensible-effects.
onException
in Control.Exception.Base seems to use SomeException
to raise exception and the Exception e =>
constraint (implicitly via catch
) to handle them
from extensible-effects.
related:
from extensible-effects.
@ibotty does the recent addition of catchDynE
let you do what you'd originally wanted here? see 60850dd for relevant usage examples
from extensible-effects.
Sorry, I missed the comment. Yes, that captures (pun intended) my intentions.
from extensible-effects.
Related Issues (20)
- Spurious ci-test-error with trace HOT 7
- RFC: Version semantics HOT 2
- Decide on: support GHC 8.0 vs use pattern synonyms in implementations HOT 7
- Undeclared `TypeApplications` extension HOT 1
- call for maintainer HOT 15
- RFC: Handle class HOT 8
- Chain multiple 'runError' calls into a single one.
- `SetMember Lift (Lift IO) r` doesn't seem to be sufficient to line up the function context for lift. HOT 4
- Build failure with GHC 8
- MonadError, MonadThrow, MonadCatch, MonadMask instances for module Exception HOT 8
- Alternative and MonadPlus instances in the module Choose HOT 2
- enable Alternative and MonadPlus instances for Choose in ghc-7.8 HOT 1
- Remove usage of deprecated OverlappingInstances HOT 4
- MonadBase and MonadBaseControl instances HOT 12
- Add explicit implementation for `*>` to be compatible with new `forever` HOT 2
- -Werror HOT 2
- Argument ordering of run* functions HOT 7
- adapt build and CI steps to use stack HOT 1
- improve performance for single-effect uses HOT 4
- Documentation: Detailed Introduction to all Effects HOT 16
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 extensible-effects.