Last active
December 14, 2017 12:41
-
-
Save int-index/fca78d931e59bdd9688054d132d4a241 to your computer and use it in GitHub Desktop.
Logging not disabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE GeneralizedNewtypeDeriving, FlexibleInstances, OverloadedStrings, UndecidableInstances #-} | |
import Control.Monad.Logger | |
import Control.Monad.Trans | |
import Control.Monad.Trans.Identity | |
import Data.Coerce | |
class Monad m => MonadFoo m where | |
foo :: m () | |
newtype FooT m a = FooT (IdentityT m a) | |
deriving (Functor, Applicative, Monad, MonadTrans, MonadLogger) | |
runFooT :: FooT m a -> m a | |
runFooT = coerce | |
instance MonadLogger m => MonadFoo (FooT m) where | |
foo = lift (logErrorN "Logging active") | |
instance {-# OVERLAPPABLE #-} (MonadFoo m, MonadTrans t, Monad (t m)) => MonadFoo (t m) where | |
foo = lift foo | |
main = runStdoutLoggingT $ runFooT $ do | |
logInfoN "Stdout logging, message displayed" | |
foo | |
runNoLoggingT $ do | |
logInfoN "No logging, this message not displayed" | |
foo |
Author
int-index
commented
Dec 14, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment