当我尝试编译代码时,发生两个错误。Haskell错误:无法匹配预期类型'ServerPartT IO a0'与实际类型'[Response]'
第一个是:
Couldn't match expected type ‘ServerPartT IO a0’
with actual type ‘[Response]’
In a stmt of a 'do' block:
msum
(map (\ (a, b) -> dir a b)
$ routes
staticDir
redirectUrlGraphEmail
redirectUrlGraphPost
aboutContents
privacyContents)
++
[do { nullDir;
seeOther "graph" (toResponse "Redirecting to /graph") },
notFoundResponse]
In the second argument of ‘($)’, namely
‘do { decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096);
msum
(map (\ (a, b) -> dir a b)
$ routes
staticDir
redirectUrlGraphEmail
redirectUrlGraphPost
aboutContents
privacyContents)
++
[do { nullDir;
.... },
notFoundResponse] }’
In a stmt of a 'do' block:
simpleHTTP serverConf
$ do { decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096);
msum
(map (\ (a, b) -> dir a b)
$ routes
staticDir
redirectUrlGraphEmail
redirectUrlGraphPost
aboutContents
privacyContents)
++
[do { nullDir;
.... },
notFoundResponse] }
它提到了码连续3个大块,其中一个
第二个是:
Couldn't match type ‘ServerPartT IO’ with ‘[]’
Expected type: [[Response]]
Actual type: [ServerPartT IO Response]
In the first argument of ‘msum’, namely
‘(map (\ (a, b) -> dir a b)
$ routes
staticDir
redirectUrlGraphEmail
redirectUrlGraphPost
aboutContents
privacyContents)’
In the first argument of ‘(++)’, namely
‘msum
(map (\ (a, b) -> dir a b)
$ routes
staticDir
redirectUrlGraphEmail
redirectUrlGraphPost
aboutContents
privacyContents)’
In a stmt of a 'do' block:
msum
(map (\ (a, b) -> dir a b)
$ routes
staticDir
redirectUrlGraphEmail
redirectUrlGraphPost
aboutContents
privacyContents)
++
[do { nullDir;
seeOther "graph" (toResponse "Redirecting to /graph") },
notFoundResponse]
我也不太清楚有关位置的错误。
看来这两个错误有完全相反的意思。我现在很困惑。任何人都可以帮助解释这一点?谢谢!
原始代码是在这里:
runServer :: IO()
runServer = do
configureLogger
staticDir <- getStaticDir
redirectUrlGraphEmail <- retrieveAuthURL testUrl
redirectUrlGraphPost <- retrieveAuthURL testPostUrl
aboutContents <- LazyIO.readFile $ markdownPath ++ "README.md"
privacyContents <- LazyIO.readFile $ markdownPath ++ "PRIVACY.md"
-- Start the HTTP server
simpleHTTP serverConf $ do
decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096)
msum
(map (\ (a, b) -> dir a b) $ routes staticDir redirectUrlGraphEmail redirectUrlGraphPost aboutContents privacyContents) ++
[ do
nullDir
seeOther "graph" (toResponse "Redirecting to /graph"),
notFoundResponse
]
其中routes
是在另一个模块:
routes :: [Char] -> T.Text -> T.Text -> Text -> Text -> [ (String, ServerPart Response)]
routes staticDir redirectUrlGraphEmail redirectUrlGraphPost aboutContents privacyContents = [
("grid", gridResponse),
("graph", graphResponse),
("image", graphImageResponse),
...
]
我只对你的代码做了一个简短的介绍,但是 - 我会怀疑'map'中的一些不正确的父类化尝试使用显式的parens而不是'$',并且看看你是否有进一步的了解。此外,我会说这不是一个最小的“非工作”的例子 - 尝试删除一切不会改变错误信息。 – epsilonhalbe