我在我的 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’
我无法理解要对我的代码进行哪些更改,以使其成为工人!