Created
March 14, 2018 11:37
-
-
Save reactormonk/de744cea375fec18b25c257ec7b43d46 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env stack | |
{- stack --install-ghc | |
--resolver lts-10.8 | |
script | |
--compile | |
--package monad-logger | |
--package katip | |
--package universum | |
--package lens | |
-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE NoImplicitPrelude #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
import Universum | |
import Control.Lens.TH | |
main = pure () | |
newtype RIO r a = RIO { runRIO :: ReaderT r IO a} deriving (Functor, Applicative, Monad, MonadReader r) | |
data Logging r = Logging | |
{ _log :: Text -> RIO r () | |
} | |
data App = App | |
{ _appLogImpl :: Logging App | |
} | |
makeLenses ''App | |
-- TH | |
instance HasLoggingImpl App where | |
logImpl = appLogImpl | |
class HasLoggingImpl r where | |
logImpl :: Lens' r (Logging r) | |
log :: HasLoggingImpl r => Text -> RIO r () | |
log t = do | |
impl <- fmap (view logImpl) ask | |
_log impl t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment