很多包装,拆包等都在使用Strings and Texts并且仍然卡住, 目标很简单,因为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)
迫切需要提示如何使其发挥作用。
答案 0 :(得分:2)
使用Data.ByteString.Lazy.Char8.pack而不是L.pack。
答案 1 :(得分:1)
这是很多包装和拆包。我没有安装wai,所以我无法测试,但这样的事情应该更简单:
application req = do
return $ responseLBS statusOK [("Content-Type", "text/plain")]
$ L.append "Hello World" $ rawPathInfo req
即。只需使用ByteString
的{{1}}而不是append
的{{1}}。