Using MonadLogger
without LoggingT
in Haskell
Using RIO with Servant in Haskell, with nested environments.
Port of servant-nested-apis Gist.
Nesting APIs and ReaderT
environments in Haskell's Servant
Environments, from parent to child (or base to extended):
App
(ReaderT AppEnv IO
):HasLogFunc env
HasDatabase env
HasTracing env
AppAuthenticated
(ReaderT AppAuthenticatedEnv IO
):HasApp env
(everything fromApp
)
Compare using a stack of transformers vs. the ReaderT pattern for a web service.
See files:
module AsyncMonadBaseControlExample where | |
import Blammo.Logging (LoggingT) | |
import Control.Concurrent.Async.Lifted.Safe (concurrently) | |
import Control.Monad.Base (MonadBase) | |
import Control.Monad.Reader (MonadIO, MonadReader, MonadTrans (lift), ReaderT) | |
import Control.Monad.Trans.Control (MonadBaseControl (liftBaseWith, restoreM), StM) | |
import Data.Text.Lazy qualified as TL | |
import Web.Scotty.Trans (ActionT, text) |
#!/usr/bin/env stack | |
{- stack | |
--resolver lts-13.4 | |
--install-ghc | |
script | |
--ghc-options "-Wall" | |
--package aeson | |
--package aeson-pretty | |
--package aeson-typescript | |
--package base |
TypeScript has support for type-checking plain JavaScript files, which is very useful if you have an existing JS codebase and you want to test the waters and gradually add types.
There are some limitations in what you can do in JSDoc, but a lot of them can be worked-around by using type-definition files .d.ts
(for example in a types/
directory). These files don't generate any JavaScript code, they are just there to provide extra type definitions to the compiler.
One thing you can't do in those .d.ts
files though, is use enums. You could define them of course, but you won't get the runtime representation since the files don't generate JS code.
CLOSURE_COMPILER_VERSION := 20180101 | |
CLOSURE_COMPILER_URL := http://dl.google.com/closure-compiler/compiler-$(CLOSURE_COMPILER_VERSION).tar.gz | |
closure-compiler: | |
mkdir -p vendor | |
curl -o vendor/closure-compiler.tar.gz $(CLOSURE_COMPILER_URL) | |
tar -C vendor/ -zxf vendor/closure-compiler.tar.gz | |
mv vendor/closure-compiler-v$(CLOSURE_COMPILER_VERSION).jar vendor/closure-compiler.jar | |
rm vendor/COPYING vendor/README.md vendor/closure-compiler.tar.gz | |
node_modules | |
dist |