2012-07-27 74 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