Replies: 11 comments 15 replies
-
Well, I thought about it, maybe I'm not correct her, LogEff is present inside the ReqEff, so probably it is quite ok then. |
Beta Was this translation helpful? Give feedback.
-
Then I will ask here another question, related at least to this sample app. Here is the interpretation and run module" module EffectfulAppEntry where
import EffectfulApp (LogEff (..), ReqEff (..), Request (..), app)
--
import Data.Function ((&))
import Effectful (
Eff,
IOE,
MonadIO (..),
runEff,
type (:>),
)
import Effectful.Dispatch.Dynamic (interpret)
runLog ::
(IOE :> es) =>
Eff (LogEff : es) a ->
Eff es a
runLog = interpret \_ -> \case
LogLine msg -> liftIO $ putStrLn msg
runReq ::
(IOE :> es) =>
Eff (ReqEff : es) a ->
Eff es a
runReq = interpret $ const \case
OnRequest toResponse ->
liftIO $ do
_ <-
runEff
( toResponse Request {reqUrl = "/some"}
& runLog
)
pure ()
main :: IO ()
main = do
runEff $
app
& runReq
-- we actually don't need logEff here but is is still can be applied
& runLog Why is it still possible to apply |
Beta Was this translation helpful? Give feedback.
-
The app :: (Req :> es) => Eff es a
app = reqItUp
blah =
app
& runReq
& runLogger then the type of Doing the extra The interpreters determining the concrete stack is very similar to how mtl-style works. |
Beta Was this translation helpful? Give feedback.
-
I understand that it does nothing, but it seems to be misleading that such thing is allowed. In mtl, as you mentioned it, we can not hae yet another |
Beta Was this translation helpful? Give feedback.
-
If you want your application to have a closed set of effects, then you need to specify that. In app :: (Req :> es) => Eff es a You are saying You could alternatively write app :: Eff '[Req] a And now That said, this isn't idiomatic. |
Beta Was this translation helpful? Give feedback.
-
Ok, I see it for the I tried to replace it with
And can not get how to put the interperter correctly. For my case the dummy interperter looks like: runReq = interpret $ const \case
OnRequest toResponse ->
liftIO $ do
_ <-
runEff
( toResponse Request {reqUrl = "/some"}
& runLog
)
pure () |
Beta Was this translation helpful? Give feedback.
-
I think we'd need to see full code that we can compile to help here, but I don't think you're going down a very productive path. This is not how |
Beta Was this translation helpful? Give feedback.
-
Indeed, what @ocharles said is accurate. Using monomorphic effect stacks isn't even supported with higher order effects (see here, specifically the last example), so you shouldn't really do things this way. Btw, I'll convert this thread to a discussion, since it's not an issue. |
Beta Was this translation helpful? Give feedback.
-
Well, there is a full code of modules that compiles in the first and the third post: modules
Could you elaborate more on what "monomorphic effect stacks" is and what is wrong with my sample's code/approach? |
Beta Was this translation helpful? Give feedback.
-
So it is ok that, to attach interpreters that are not needed (won't be used) by the program at the moment? Is there a rationale behind this? |
Beta Was this translation helpful? Give feedback.
-
Can you try and explain what the problem you see is? There is an almost insignificant performance hit and that's it |
Beta Was this translation helpful? Give feedback.
-
I would like to model a sample app here, one of the functions of it is to be able handle the request and return the response. In this model, it uses the effectful method
onRequest
to which we pass the handler (response returned will be converted to IO by interpreter and run on each request).The problem I see here is that the
app
function in this case doesn't requireLogEff
effect constraint, which is used in the handler but is not used in the application monadic flow directly, it is only passed to handler here.In my view, the
app's
signature doesn't reflect what the app is doing as a whole in this case. It reflects what the monadic flow is doing, not the app. What would you say about such an issue? Maybe it is possible somehow to achieve what I would like to see in this case?Beta Was this translation helpful? Give feedback.
All reactions