对字符串和文本进行了大量的打包、解包等操作,但仍然卡住了, 目标很简单,就像连接额外的请求信息的 hello world 一样:
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp (run)
import Network.HTTP.Types (statusOK)
import qualified Data.ByteString.Lazy as L
import Data.ByteString.Char8 (unpack)
import qualified Data.Text.Lazy as T
application req = do
return $ responseLBS statusOK [("Content-Type", "text/plain")]
$ L.pack $ "Hello World" ++ (unpack $ rawPathInfo req)
main = run 3000 application
产生:
Couldn't match expected type `GHC.Word.Word8'
against inferred type `Char'
Expected type: [GHC.Word.Word8]
Inferred type: [Char]
In the second argument of `(++)', namely
`(unpack $ rawPathInfo req)'
In the second argument of `($)', namely
`"Hello World" ++ (unpack $ rawPathInfo req)
急切需要提示如何使其工作。
最佳答案
使用 Data.ByteString.Lazy.Char8.pack 而不是 L.pack。
关于 haskell 。 WAI 简单 Web 应用程序出现问题(解压字节串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7497881/