2012-07-27 58 views
1
main :: IO() 
main = do 
    let a = ("teeeeeeeeeeeeest","teeeeeeeeeeeest") 
    b <- app a 
    print b 

的應用希望(字節字符串,字節字符串)不是([字符],[字符]) 我怎麼能轉換嗎?哈斯克爾[字符]以字節串

回答

7

您可以轉換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