HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleco-log-polysemy-0.0.1.4Haskell2010

Colog.Polysemy.Effect

SPDX-License-Identifier : MPL-2.0 Maintainer : Co-Log xrom.xkov@gmail.com Stability : Provisional Portability : Portable

This module contains logging effect which can be interpreted in terms of LogAction from the co-log-core package.

  • 2 types
  • 7 values

Effect

1 declaration
datadata Log msg (m :: Type -> Type) a where
#

Effect responsible for logging messages of type msg. Has similar structure to LogAction.

You can think of this effect in the following way in terms of the existing effects in polysemy:

  1. Like Output but specialised for logging.

  2. Like Trace but polymorphic over logged message.

Constructors

Actions

1 declaration
valuelog
  1. :: Member (Log msg) r
  2. => msg

    Message to log

  3. -> Sem r ()

    Effectful computation with no result

#

Log a message. If you semantic monad Sem has effect Log then you can send messages of type msg to that effect. This function can be used like this:

application :: Member (Log String) r => Sem r ()
application = do
    log "Application started..."
    log "Application finished..."

Direct usages

2 declarations

Interpretations

3 declarations
valuerunLogAction
  1. :: Member (Embed m) r
  2. => LogAction m msg
  3. -> Sem (Log msg ': r) a
  4. -> Sem r a
#

Run a Log effect in terms of the given LogAction. The idea behind this function is the following: if you have LogAction m msg then you can use this action to tell how to io interpret effect Log. However, this is only possible if you also have Lift m effect because running log action requires access to monad m.

This function allows to use extensible effects provided by the polysemy library with logging provided by co-log. You can construct LogAction independently and then just pass to this function to tell how to log messages.

Several examples:

  1. runLogAction mempty: interprets the Log effect by ignoring all messages.

  2. runLogAction logStringStdout: interprets Log effect by allowing to log String to stdout.

Interpretations for Other Effects

2 declarations
valuerunOutputAsLog :: Member (Log msg) r => Sem (Output msg ': r) a -> Sem r a
#

Run Output as the Log effect. This function can be useful if you have an interpreter for the Log effect and you want to log messages using that interpreter.