main :: IO ()
main = do
let a = ("teeeeeeeeeeeeest","teeeeeeeeeeeest")
b <- app a
print b
应用程序期望 (bytestring,bytestring) 而不是 ([char],[char]) 我该如何转换它?
main :: IO ()
main = do
let a = ("teeeeeeeeeeeeest","teeeeeeeeeeeest")
b <- app a
print b
应用程序期望 (bytestring,bytestring) 而不是 ([char],[char]) 我该如何转换它?
如果您只包含 ASCII 值或者您只对每个 s 的最后八位感兴趣,您可以将String
s 转换为ByteString
s with Data.ByteString.Char8.pack
(或其惰性ByteString
版本),String
Char
import qualified Data.ByteString.Char8 as C
main :: IO ()
main = do
let a = ("teeeeeeeeeeeeest","teeeeeeeeeeeest")
b <- app $ (\(x,y) -> (C.pack x, C.pack y)) a
print b
如果您String
包含非 ASCIIChar
并且您不仅对最后八位感兴趣,那么您将需要一些其他编码,例如Data.ByteString.UTF8.fromString
.
你可以试试:
import qualified Data.ByteString.Char8 as B --to prevent name clash with Prelude
B.pack "Hello, world"
在这里可以找到很多有用的功能:
http://www.haskell.org/ghc/docs/latest/html/libraries/bytestring/Data-ByteString-Char8.html
你也可以Data.ByteString.Lazy.Char8
用于惰性字节串