Is there a way to write an interpreter for log-effectful? #155
Replies: 3 comments 4 replies
-
Looking through issues I see a Console effect was recommended like Polysemy's trace here. It looks like this Console effect is added in a recent PR as well. However I was hoping for the ability to purely use log-base so I could have different log levels. I would like to use one of the log levels for tests along with a writer monad. |
Beta Was this translation helpful? Give feedback.
-
I haven't worked out where to put this comment, but I think the Haskell community is a bit too focused on creating pure variants of interpreters. This is one way to do it, but I find the approach outlined in https://www.jamesshore.com/v2/projects/nullables/testing-without-mocks to be a better one. Though this is a bit OO-centric, the general idea when applied to effects is that we don't want to replace entire effects, but rather we want to run an effect with a pure backing. When we take this stance, newNullLogger :: IO Logger
newNullLogger = mkLogger mempty mempty
foo = do
logger <- newNullLogger
runEff $ runLog mempty logger minBound $ app |
Beta Was this translation helpful? Give feedback.
-
If you want to collect logs instead of displaying them, there are appropriate loggers for this purpose - see |
Beta Was this translation helpful? Give feedback.
-
I feel like there is an easy way to do this that I'm somehow missing. I guessed at this solution:
After reading Effectful.Dispatch.Static and seeing how runLog is defined.
Or maybe no one else has a use for a pure interpreter?
Do others not test their effectful programs that use logs or does everyone roll their own logging effect?
Beta Was this translation helpful? Give feedback.
All reactions