Trying to convert a bytestring to a hex ascii string display
wordtoascii :: Int -> String
wordtoascii y =
showIntAtBase 16 intToDigit ( fromEnum y) ""
bs2string :: Data.ByteString.ByteString -> String
bs2string bs = do
Prelude.map( wordtoascii,
(unpack bs))
Type error:
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)) }
This is not the syntax for what you think it is.
That is the same as:
Remove the parentheses and the comma.
However, this is also wrong. Because the type of the above expression is
[String], notString. You wantconcatMap, which is likemapbut splices the results together in one string.Or, even better,
The comma is for creating tuples, lists, and records. For example,
(1, 7) :: (Int, Int)could be cartesian coordinates. The comma does not appear in function calls.Typically,
ByteStringis imported only as a qualified import, since so many functions clash withPrelude. This eliminates the need forPrelude.qualification on the functions that do clash.The
Sstands forStrict.BSis also a common choice, it stands for for Bytestring (Strict).