main :: IO()
main = do
let a = ("teeeeeeeeeeeeest","teeeeeeeeeeeest")
b <- app a
print b
的應用希望(字節字符串,字節字符串)不是([字符],[字符]) 我怎麼能轉換嗎?哈斯克爾[字符]以字節串
main :: IO()
main = do
let a = ("teeeeeeeeeeeeest","teeeeeeeeeeeest")
b <- app a
print b
的應用希望(字節字符串,字節字符串)不是([字符],[字符]) 我怎麼能轉換嗎?哈斯克爾[字符]以字節串
您可以轉換String
s到ByteString
s的Data.ByteString.Char8.pack
(或其懶惰ByteString
版)如果您的String
只包含ASCII值,或者你感興趣的只是每個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
包含非ASCII Char
,並且您只對最後8位感興趣,則需要其他編碼,如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
懶惰的字節串