Skip to content

Instantly share code, notes, and snippets.

@reactormonk
Created March 14, 2018 11:37
Show Gist options
  • Save reactormonk/de744cea375fec18b25c257ec7b43d46 to your computer and use it in GitHub Desktop.
Save reactormonk/de744cea375fec18b25c257ec7b43d46 to your computer and use it in GitHub Desktop.
#!/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