
Hi all, I've never found an easy way to deal with ByteStrings. I'm using the RSA library and it en- and decodes Data.ByteString.Lazy.ByteString. I initially start with Strings, ie. [Char], but there is no function to convert the 2 back and forth. There is however a function which takes [Word8] to BytesString and back. It all wouldn't be so confusing if there weren't several versions of ByteString in several modules to choose from. And a number of libraries requiring different types of ByteString. I am sure the designers of the bytestring package had good reason for this design, is there also a webpage which explains which one to use and under what circumstances? Günther

Look in Data.ByteString.Char8 Cheers, Greg On Apr 5, 2010, at 6:27 PM, Günther Schmidt wrote:
Hi all,
I've never found an easy way to deal with ByteStrings.
I'm using the RSA library and it en- and decodes Data.ByteString.Lazy.ByteString.
I initially start with Strings, ie. [Char], but there is no function to convert the 2 back and forth. There is however a function which takes [Word8] to BytesString and back.
It all wouldn't be so confusing if there weren't several versions of ByteString in several modules to choose from. And a number of libraries requiring different types of ByteString.
I am sure the designers of the bytestring package had good reason for this design, is there also a webpage which explains which one to use and under what circumstances?
Günther
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

2010/4/6 Günther Schmidt
I initially start with Strings, ie. [Char], but there is no function to convert the 2 back and forth. There is however a function which takes [Word8] to BytesString and back.
The problem is one of encoding. If you use the Char8 Bytestring variants, then pack and unpack will return Strings... as long as you're OK using only those characters that can fit in 8 bytes. utf8-string lets you do conversions to/from Bytestring if you know the String in question is UTF-8; otherwise, if you use the Text library you have a variety of encodings to choose from. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

gue.schmidt:
Hi all,
I've never found an easy way to deal with ByteStrings.
I'm using the RSA library and it en- and decodes Data.ByteString.Lazy.ByteString.
I initially start with Strings, ie. [Char], but there is no function to convert the 2 back and forth. There is however a function which takes [Word8] to BytesString and back.
It all wouldn't be so confusing if there weren't several versions of ByteString in several modules to choose from. And a number of libraries requiring different types of ByteString.
I am sure the designers of the bytestring package had good reason for this design, is there also a webpage which explains which one to use and under what circumstances?
As a general rule you should never convert between String and bytestring. You can read bytestrings from files, or write literals using "pack" or the -XOverloadedStrings extension Converting between lazy and strict bytestrings is a representation change, and changes complexity - so be aware of what you're doing. You can do this via fromChunks or concat . toChunks. -- Don

Hi Don Stewart wrote:
gue.schmidt:
Hi all,
I've never found an easy way to deal with ByteStrings.
I'm using the RSA library and it en- and decodes Data.ByteString.Lazy.ByteString.
I initially start with Strings, ie. [Char], but there is no function to convert the 2 back and forth. There is however a function which takes [Word8] to BytesString and back.
It all wouldn't be so confusing if there weren't several versions of ByteString in several modules to choose from. And a number of libraries requiring different types of ByteString.
I am sure the designers of the bytestring package had good reason for this design, is there also a webpage which explains which one to use and under what circumstances?
I really would like such a webpage, because I am also confused about when to use what type of strings.
As a general rule you should never convert between String and bytestring. You can read bytestrings from files, or write literals using "pack" or the -XOverloadedStrings extension
Except that different libraries require different kind of strings. Some use strict bytestring, some use lazy bytestring, some use [Char], some use lazy Data.Text, ... So you really need to convert between different representations. It may seem unfair that I put byte-strings and char-strings in the same bucket, but libraries do use byte-strings to contain characters. For example, Parsec has a [Char] and a bytestring interface. Strings are the glue that binds many libraries together, and the many different types of strings complicate this glue. It is therefore much more complicated to compose different libraries than it was when most libraries used [Char]. It really would make Haskell programming easier if we could settle on one char-string type (and one type for byte-strings).
Converting between lazy and strict bytestrings is a representation change, and changes complexity - so be aware of what you're doing. You can do this via fromChunks or concat . toChunks.
Reading the introduction to lazy bytestring here http://hackage.haskell.org/packages/archive/bytestring/0.9.1.5/doc/html/Data... it seems that lazy bytestring always has at least as good complexity as strict bytestrings. Lazy Data.Text strings also has at least as good complexity as strict Data.Text strings. So, for public library interfaces it would be great if could settle for some lazy string type like Data.Text. Preferably a string type that could be efficiently converted to lazy bytestrings for libraries that deal with bytes and not characters. This however, requires that the community can settle for one char-string type and a good beginning could be a description of how string handling is supposed to happen in Haskell (I am thinking about a webpage like Günther writes about). /Mads
-- Don _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Mads Lindstrøm
It may seem unfair that I put byte-strings and char-strings in the same bucket, but libraries do use byte-strings to contain characters. For example, Parsec has a [Char] and a bytestring interface.
It bears noting that Data.ByteString and Data.ByteString.Char8 are just different interfaces to the same data type (same goes for the .Lazy versions). Once upon a time I forked bytestring to use a phantom type tag to separate different encodings (including many other 8-bit encodings than the Char8 one), but although I still think this is a good idea, the code is long dead and gone now. -k -- If I haven't seen further, it is by standing in the footprints of giants
participants (6)
-
Don Stewart
-
Gregory Crosswhite
-
Günther Schmidt
-
Ivan Miljenovic
-
Ketil Malde
-
Mads Lindstrøm