Replies: 1 comment
-
On taking another look at this, I think it's very possible I've simply "switched" the directions of borrow/lend / lift/unlift in my head... I've just tried rewriting it as: [...]
UnliftResponse ->
localSeqUnlift env $ \unlift ->
localSeqLend @'[ScottyIO] env $ \lend ->
fmap (. raise) . unlift . lend $ defaultUnliftResponse and this compiles. So it seems I just totally confused myself and in fact was supposed to transform the input parameter of the unlift response function to Just wanted to say thanks for writing this brilliant library! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I just wanted to start off by mentioning I haven't been using
effectful
for that long so it's possible I'm missing something crucial here. So the TLDR is that I'm trying to essentially wrap the monad transformer typeScottyT
fromscotty
witheffectful
, so that I can have a givenEff es
monad inActionT m a
context and thus run all the stuff I need to do like talking to the DB and such without having to unlift every single thing toIO
or sprinkleIOE :> es
everywhere (scotty
needsm
inActionT m a
to have an instance ofMonadUnliftIO
). Most of the work is done for this, but I'm just playing around with including what is essentially an effect action likeUnliftResponse :: m (m Response -> IO Response)
in my effect, and how exactly to deal with lifting the inner monad during handling.The setup looks like so:
ScottyIO
effect:This effect is essentially just a marker to let me write a newtype monad transformer
ScottyInner
(see below) with its ownMonadIO
andMonadUnliftIO
instances when theScottyInner
-transformed monad is someEff es
whereScotty :> es, ScottyIO :> es
(Scotty
here necessary as I pass some options through that - right now this is anUnliftStrategy
for theMonadUnliftIO
instance).Just as a small explanation, I'm creating
MonadIO
andMonadUnliftIO
instances since those are constraints are imposed by my usage ofscotty
.Scotty
effect:... where
ScottyOpts
is just a product type with some field optics defined (fromoptics
):Now, the issue I have is in the handler for this
Scotty
effect. Here's what I'm currently working with:defaultUnliftResponse
just presents the unlifting function provided within theMonadUnliftIO
instance forScottyInner
wherem ~ Eff es, Scotty :> es, ScottyIO :> es
inScottyInner m
(so essentially the(unlift . runInner)
expression below):Now, my issue is that I get the following error:
So I'm calling the
borrow
function handed out bylocalSeqBorrow
in order to cleave off theScotty
effect from the outer monad fromdefaultUnliftResponse
(i.e.Eff (Scotty : es) (Eff (Scotty : es) Response -> IO Response)
toEff es (Eff (Scotty : es) Response -> IO Response)
whereScottyIO :> es
), and after I'm trying to compose withraise
such that I can return theEff es Response -> IO Response
function required to match the signature ofUnliftResponse :: m (m Response -> IO Response)
.I'm simply struggling to wrap my head around how this equality constraint
localEs ~ es
has even been introduced. Is it an issue with callingraise
? I can't see any other way to return the required function, sinceborrow :: forall a. Eff ('[Scotty] ++ es) a -> Eff es a
(wrong way round) and callingrunWithOpts :: ScottyOpts -> Eff (Scotty : es) -> Eff es
also wouldn't work (again, wrong way round).In the end the point is to be able to write something like this to turn a
scotty
router into a WAI application to then run manually on WARP or something:Sorry that my explanation has been super long and I suppose it's a somewhat contrived example since for all intents and purposes I'll probably only be switching out the relevant
UnliftStrategy
for unlifting theResponse
actions, but in a sense this has become a bit of a learning example for how to use the library more generally, so any help decoding this error would be greatly appreciated.Beta Was this translation helpful? Give feedback.
All reactions