Hi,
Thanks to Alp, I had a working example:
#!/usr/bin/env stack
-- stack --resolver lts-8.24 runghc --package mtl --package monad-logger --package warp --package servant-server
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.Logger (LoggingT, logInfo, runStdoutLoggingT)
import Control.Monad.Except (ExceptT)
import Control.Monad.Reader (ReaderT, runReaderT)
import qualified Network.Wai.Handler.Warp as Warp
import Servant hiding (Handler)
import qualified Control.Category as C
type Handler = ReaderT String (ExceptT ServantErr (LoggingT IO))
type API = Get '[PlainText] String
api :: Proxy API
api = Proxy
loggingServer :: ServerT API Handler
loggingServer = success
success :: Handler String
success = do
$(logInfo) "test"
pure "success"
main :: IO ()
main = do
let nt = hoistNat (Nat runStdoutLoggingT) C.. Nat (`runReaderT` "someString")
server = nt `enter` loggingServer
Warp.run 8080 $ serve api server
Now if I try to upgrade to lts-9.2 (with servant-0.11 instead of servant-0.9),
I get:
test.hs:34:24: error:
Data constructor not in scope:
Nat :: (LoggingT m0 a0 -> m0 a0) -> m1 :~> n
test.hs:34:51: error:
Data constructor not in scope:
Nat :: (ReaderT [Char] m2 a1 -> m2 a1) -> a :~> t m1
test.hs:36:31: error:
• Couldn't match type ‘Servant.Utils.Enter.Entered
m3
(t0 n0)
(ReaderT String (ExceptT ServantErr (LoggingT IO)) [Char])’
with ‘Servant.Server.Internal.Handler.Handler [Char]’
Expected type: Server API
Actual type: Servant.Utils.Enter.Entered
m3
(t0 n0)
(ReaderT String (ExceptT ServantErr (LoggingT IO)) [Char])
The type variables ‘m3’, ‘t0’, ‘n0’ are ambiguous
• In the second argument of ‘serve’, namely ‘server’
In the second argument of ‘($)’, namely ‘serve api server’
In a stmt of a 'do' block: Warp.run 8080 $ serve api server
• Relevant bindings include
server :: Servant.Utils.Enter.Entered
m3
(t0 n0)
(ReaderT String (ExceptT ServantErr (LoggingT IO)) [Char])
(bound at test.hs:35:9)
The first errors are easy to fix, by converting Nat to NT, but I don't get how
to fix the last one... I've tried to look at the modifications to Handler
and Enter, without success so far. Could someone help me on this?
You can find the example code with the lts-8.24 -> lts-9.2 and Nat -> NT
conversion attached, just run `stack test.hs` to compile it.
Thanks!
--
Félix