Decorator-style handler #298
Replies: 4 comments 3 replies
-
In a more generic fashion, the runLoggerAbove severity impl1 impl2 = interpret $ \_ -> \case
Log severity message -> do
if severity > minSeverity then do
-- use `impl1` as handler
else do
-- use `impl2` as handler |
Beta Was this translation helpful? Give feedback.
-
Ok, after some debugging I realized that runLoggerAbove :: (Logger :> es) => Severity -> Eff (Logger : es) a -> Eff es a
runLoggerAbove minSeverity = interpret $ \_ -> \case
Log severity message -> do
when (severity > minSeverity) $ do
log severity message |
Beta Was this translation helpful? Give feedback.
-
This leaves the question open as to how to deal with the "generic" approach that supports passing handlers as arguments, and decides which one to use based on the |
Beta Was this translation helpful? Give feedback.
-
Have a look at |
Beta Was this translation helpful? Give feedback.
-
I'm trying to get the following code to compile:
The idea is that we have a single effect
Logger
which accepts multiple interpretations, for example, we might have a logger that does not log anything (runNoLogger
) or a logger which writes to a file (runHandleLogger
).Now, I would like to have a "handler" that works like a Decorator, that is, the "handler" requires another "handler" that actually does the work, but before (or after) this "inner" handle takes control the Decorator performs some kind of (pre/post)processing. In this case, I would like to have a decorator
runLoggerAbove
that when theseverity
is some value it delegates the work to "inner", otherwise it does nothing (return ()
).The code above does not compile with the following error:
My
.cabal
file looks like this:My environment:
Beta Was this translation helpful? Give feedback.
All reactions