Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell [char] to bytestring

Tags:

haskell

main :: IO ()
main = do 
    let a = ("teeeeeeeeeeeeest","teeeeeeeeeeeest")
    b <- app a
    print b

app expects (bytestring,bytestring) not ([char],[char]) how can I convert it?

like image 380
Gert Cuykens Avatar asked Dec 04 '22 15:12

Gert Cuykens


1 Answers

You can convert Strings to ByteStrings with Data.ByteString.Char8.pack (or the lazy ByteString version thereof) if your String contains only ASCII values or you are interested only in the last eight bits of each 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

If your String contains non-ASCII Chars and you are interested in more than only the last eight bits, you will need some other encoding, like Data.ByteString.UTF8.fromString.

like image 67
Daniel Fischer Avatar answered Jan 05 '23 12:01

Daniel Fischer