Skip to content

Making a function pure by discarding logs #224

Answered by chshersh
qwbarch asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @qwbarch 👋🏻

The logMessagePure function is polymorphic over the message type:

logMessagePure :: Monad m => LogAction (PureLoggerT msg m) msg

Because of how type inference works, Haskell is not able to infer that msg is the same as Message in your example. A simple solution would be to give Haskell hint by specifying the type of logMessagePure explicitly:

zero :: Int
zero = fst . runPureLog $ usingLoggerT (logMessagePure :: LogAction (PureLogger Message) Message) zeroM

Alternatively, you can enable the TypeApplications extension and specify this type a bit shorter:

zero = fst . runPureLog $ usingLoggerT (logMessagePure @_ @Message) zeroM

Moreover, there's even a better way to ignore lo…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@qwbarch
Comment options

Answer selected by qwbarch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
pure Pure logging
2 participants