Comments (1)
@srid I'm not quite sure that I understand your question. Maybe you can provide an example of code that you have a problem with? I will write some of my thoughts meanwhile.
The recommended approach of using co-log
in applications is to introduce an environment, parametrised by a monad:
data Env (m :: Type -> Type) = Env
{ envLogAction :: LogAction m MyMessage
, envPort :: Int
}
And then use it inside the ReaderT
monad:
newtype App a = App
{ unApp :: ReaderT (Env App) IO a
} deriving newtype (Functor, Applicative, Monad, MonadIO, MonadReader (Env App), MonadUnlift IO)
You can then use the asks
function to get LogAction
and, indeed, you can use the withRunInBase
function to run the logger inside the IO
monad:
foo :: App ()
foo = do
LogAction log <- asks envLogAction
withRunInBase $ \runInBase -> withCurrentDirectory "/some/path" $ do
runInBase $ log "Running from directory: /some/path"
... ordinary actions in the IO monad ...
runInBase $ log "Finishing actions in the directory: /some/path"
Does this help with your question?
An example of using co-log
with MonadUnlift
would be nice, but I think it should be in the co-log
repository (probably as a separate tutorial). A tutorial on MonadUnlift
alone would be nice as well, and we do have plans to write a more detailed tutorial with examples on the subject.
from unlift.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unlift.