我在Haskell项目中使用了堆栈lts-8.6。下面是我用lts-8.6正确编译的代码:
type AppM = ReaderT App (ExceptT ServantErr IO)
type ServletAPI = ResourcesAPI
:<|> MapTitleAPI
server :: ServerT ServletAPI AppM
server = serverResourcesAPI
:<|> serverMapTitleAPI
type API = ServletAPI
:<|> Raw
runWebServerNibes :: App
-> IO ()
runWebServerNibes app = do
run (app_portServer . app_serverHTTP . appSettings $ app) $ appNubes app
appNubes :: App -> Application
appNubes app = serve api (readerServer app)
readerServer :: App -> Server API
readerServer app = enter (readerToExcept app) server
:<|> serveDirectory (app_pathFolderStatic . app_serverHTTP . appSettings $ app)
readerToExcept :: App -> AppM :~> ExceptT ServantErr IO
readerToExcept app = Nat $ \x -> runReaderT x app
api :: Proxy API
api = Proxy
对于lts-9.3,我将Nat
替换为NT
。
但是当我使用lts-9.3时,我收到一个错误:
• Couldn't match type ‘ImportWSN.Handler’
with ‘ExceptT ServantErr IO’
arising from a functional dependency between:
constraint ‘Servant.Utils.Enter.Enter
(ReaderT App IO Data.Text.Internal.Text)
(ReaderT App IO)
(ExceptT ServantErr IO)
(ImportWSN.Handler Data.Text.Internal.Text)’
arising from a use of ‘enter’
instance ‘Servant.Utils.Enter.Enter (m a) m n (n a)’
at <no location info>
• In the first argument of ‘(:<|>)’, namely
‘enter (readerToExcept app) server’
In the expression:
enter (readerToExcept app) server
:<|>
serveDirectory
(app_pathFolderStatic . app_serverHTTP . appSettings $ app)
In an equation for ‘readerServer’:
readerServer app
= enter (readerToExcept app) server
:<|>
serveDirectory
(app_pathFolderStatic . app_serverHTTP . appSettings $ app)
和
• Couldn't match type ‘IO’ with ‘ExceptT ServantErr IO’
Expected type: ReaderT App (ExceptT ServantErr IO) x
Actual type: AppM x
• In the first argument of ‘runReaderT’, namely ‘x’
In the expression: runReaderT x app
In the second argument of ‘($)’, namely ‘\ x -> runReaderT x app’
我无法理解对我的代码所做的更改,以便它成为一名工作人员!