当我尝试编译代码时,出现两个错误。
第一个是:
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] }
它提到了三块代码,其中一个
第二个是:
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),
...
]