Wenn ich versuchte, den Code zu kompilieren, treten zwei Fehler auf.Haskell Fehler: konnte den erwarteten Typ 'ServerPartT IO a0' mit dem tatsächlichen Typ '[Antwort]' nicht übereinstimmen
die erste ist:
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] }
Es genannten drei Teile des Codes, die man
das zweite ist:
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]
Ich bin auch nicht ganz sicher über die Lage des Fehlers.
Es scheint, dass diese beiden Fehler völlig entgegengesetzte Bedeutungen haben. Jetzt bin ich verwirrt. Kann mir jemand helfen, das zu erklären? Vielen Dank!
Der ursprüngliche Code ist hier:
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
]
wo routes
in einem anderen Modul ist:
routes :: [Char] -> T.Text -> T.Text -> Text -> Text -> [ (String, ServerPart Response)]
routes staticDir redirectUrlGraphEmail redirectUrlGraphPost aboutContents privacyContents = [
("grid", gridResponse),
("graph", graphResponse),
("image", graphImageResponse),
...
]
Ich hatte nur einen kurzen Blick auf Ihren Code aber - ich würde vermuten, dass einige falsche Elternung in der 'map' versuchen, explizite Parens anstelle von' $ 'zu verwenden und sehen, ob Sie weiterkommen. Ich würde auch sagen, dass dies kein minimales "nicht funktionierendes" Beispiel ist - versuchen Sie alles zu entfernen, was die Fehlermeldungen nicht ändert. – epsilonhalbe