从 servant-0.4.4.7 迁移到 servant-0.7.1

Migration from servant-0.4.4.7 to servant-0.7.1

我用的是servant-0.4.4.7。下面是我的模型代码:

type API = ServletAPI :<|> Raw

type AppM = ReaderT Config (EitherT ServantErr IO)

runApplication :: IO ()
runApplication = do 
    configApp <- initializationConfig
    case configApp of
        ConfigNull  -> return ()
        otherwise   -> run (opt_portServer . cfg_optionsArg $ configApp) $ app configApp

app :: Config -> Application
app configApp = serve api (readerServer configApp)

readerServer :: Config -> Server API
readerServer configApp = enter (readerToEither configApp) server
                    :<|> serveDirectory (opt_pathFolderStatic . cfg_optionsArg $ configApp)

readerToEither :: Config -> AppM :~> EitherT ServantErr IO
readerToEither configApp = Nat $ \x -> runReaderT x configApp

api :: Proxy API
api = Proxy

这段代码 worked.But 当我使用 servant-0.7.1 时,我得到错误:

Couldn't match type ‘Control.Monad.Trans.Except.ExceptT
                           ServantErr IO’
                   with ‘EitherT ServantErr IO’
    arising from a functional dependency between:
      constraint ‘Servant.Utils.Enter.Enter
                    (ReaderT Config (EitherT ServantErr IO) Data.Text.Internal.Text)
                    (AppM :~> EitherT ServantErr IO)
                    (Control.Monad.Trans.Except.ExceptT
                       ServantErr IO Data.Text.Internal.Text)’

我知道类型不匹配,但我不明白如何解决。

谢谢!

将所有 EitherT 更改为 ExceptT(从 Control.Monad.Trans.Excepttransformers)应该可以解决问题。 EitherT 来自 either 包,已被折叠到 transformers(在名称 ExceptT 下),所以 servant,随着越来越多的包,迁移到 ExceptT