试图字节字符串转换为十六进制的ASCII字符串显示有关Word8和Int
wordtoascii :: Int -> String
wordtoascii y =
showIntAtBase 16 intToDigit (fromEnum y) ""
bs2string :: Data.ByteString.ByteString -> String
bs2string bs = do
Prelude.map(wordtoascii,
(unpack bs))
类型错误类型错误:
Couldn't match expected type `a -> b'
against inferred type `(Int -> String, [GHC.Word.Word8])'
In the first argument of `Prelude.map', namely
`(wordtoascii, (unpack bs))'
In the expression: Prelude.map (wordtoascii, (unpack bs))
In the expression: do { Prelude.map (wordtoascii, (unpack bs)) }
有趣...在我修复后,我仍然得到一个转换错误,因为“无法匹配 - 预期的Int对于intferred类型GHC.Word.Word8”。 –
那么,使用'(wordtoascii。fromIntegral)'而不是'wordtoascii'。 'fromIntegral'函数非常非常方便。它也很好地优化。 –