Is there an append statement for a ByteString?

For String, there is ++ , which is of type

 > :t (++) (++) :: [a] -> [a] -> [a] 

Obviously this does not work on ByteString because it is not a list. I see the append function, but is there an operator for it?

+7
haskell concatenation bytestring
source share
1 answer

ByteString has an instance of Monoid, so it can be combined in the usual way of combining monoids using (Data.Monoid.<>) .

The same statement also works for strings, because String ~ [Char] and [a] has an instance of Monoid, where (<>) = (++) .

 Prelude Data.Monoid Data.ByteString.Char8> unpack $ pack "abc" <> pack "def" "abcdef" 

Here I convert two strings to ByteStrings, combine them like ByteStrings, and then convert back to String to demonstrate that it worked.

+14
source share

All Articles