Questions tagged [bytestring]

A time and space-efficient implementation of byte vectors for Haskell.

A time and space-efficient implementation of byte vectors using packed Word8 arrays, suitable for high performance use, both in terms of large data quantities, or high speed requirements. Byte vectors are encoded as strict Word8 arrays of bytes, and lazy lists of strict chunks, held in a ForeignPtr, and can be passed between C and Haskell with little effort. Documentation can be found at the bytestring hackage page.

206 questions
2
votes
2 answers

Haskell avoiding stack overflow in folds without sacrificing performance

The following piece of code experiences a stack overflow for large inputs: {-# LANGUAGE DeriveDataTypeable, OverloadedStrings #-} import qualified Data.ByteString.Lazy.Char8 as L genTweets :: L.ByteString -> L.ByteString genTweets text | L.null…
Leif Grele
  • 223
  • 1
  • 5
2
votes
1 answer

Using Data.Binary.decodeFile, encountered error "demandInput: not enough bytes"

I'm attempting to use the encodeFile and decodeFile functions in Data.Binary to save a very large datastructure so that I don't have to recompute it every time I run this program. The relevant encoding- and decoding-functions are as…
Maxander
  • 395
  • 2
  • 10
2
votes
4 answers

ByteString histogram

Given a (strict) ByteString, what is the most efficient way to count how many of each possible byte it contains? I see that sort is supposed to implemented as a counting sort - but there doesn't appear to be a way to access the associated counts. I…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
2
votes
1 answer

Haskell unicode pattern matching

I am about to start developing an application in Haskell that requires some Unicode support. How to perform Unicode pattern matching in Haskell? I saw the GHC's syntax extension. But is there any language level support to perform this (without…
Tem Pora
  • 2,043
  • 2
  • 24
  • 30
2
votes
3 answers

Get Arbitrary Slices of Bits from Bytestring

I want to use a lazy Bytestring to represent a stream of bits. I need to be able to take arbitrary slices of bits from this stream efficiently. For example, I might have a ByteString of length 10, and I'd like slice a new ByteString consisting of…
cdk
  • 6,698
  • 24
  • 51
2
votes
3 answers

Casting an mmapped ByteString to other types?

I realize this may be a rather heretical question, but I wonder whether I can mmap a file of data, via System.IO.Posix.MMap, and then cast the resulting ByteString into a strict array of some other type? Eg. if I know that the file contains doubles,…
billt
  • 117
  • 5
2
votes
5 answers

Mysterious word ("LPS") appears in a list of Haskell output

I am new to Haskell and trying to fiddle with some test cases I usually run into in the real world. Say I have the text file "foo.txt" which contains the following: 45.4 34.3 377.8 33.2 98.4 456.7 99.1 44.2 395.3 I am trying to produce the…
jparanich
  • 8,372
  • 4
  • 26
  • 34
2
votes
1 answer

How do I work with indvidual elements of a ByteString in Haskell

I need to write a function with the following type replaceSubtrie :: SSTrie -> Data.Word.Word8 -> SSTrie -> SSTrie replaceSubtrie trie base subtrie = ??? where depending on the value of base, the subtrie will be inserted into the trie in differing…
JonathanZ
  • 1,046
  • 11
  • 20
2
votes
3 answers

High CPU usage on hFlush in Haskell

I found that the following Haskell code uses 100% CPU and takes about 14secs to finish on my Linux server. {-# LANGUAGE OverloadedStrings #-} module Main where import qualified Data.ByteString.Lazy.Char8 as L import System.IO str = L.pack…
beketa
  • 56
  • 4
2
votes
1 answer

returning a list of a type from parsing a byte stream in which the length is not known until runtime

I think this is more of my lack of understanding the intricacy of Types than anything else. Trying to solve this I feel that I've been close a couple of times but not there yet. I am trying to read from a stream using Data.Binary. I've reached a…
M15K
  • 185
  • 5
1
vote
2 answers

How do I convert a ByteString to an appropriately sized Word?

Basically I've read in 5 bytes that correspond to a quantity, but I would like to convert it to a Word64. What's the best way to do this? Edit: I should also say that this is run in an inner loop so performance is critical. Ideally I'd like to do…
nimish
  • 4,755
  • 3
  • 24
  • 34
1
vote
1 answer

Efficient way to combine a lazy ByteString and a lazy Text

I'm writing some code that is rendering an HTML page (via servant, if that's relevant), and for various complicated reasons, I have to construct the HTML by "combining" two segments. One segment is fetched from an internal HTTP API which returns a…
Saurabh Nanda
  • 6,373
  • 5
  • 31
  • 60
1
vote
0 answers

Haskell package Data.ByteString Issue

So I seen another post where somebody figured this out but they just said they figured it out and I can't. I need Data.ByteString for a project I'm working on to read a binary file. I get this error on my Main.hs. Could not load module…
1
vote
1 answer

Using OverloadedStrings with ByteString type

I would like to input a string from the console and output a JSON string. {-# LANGUAGE OverloadedStrings #-} module Main where import Data.Aeson import Data.Map.Strict main :: IO () main = interact $ encode This code fails. Of…
F. Zer
  • 1,081
  • 7
  • 9
1
vote
1 answer

Haskell Bytestring pack/unpack

I still don't get how bytestrings work import qualified Data.ByteString.Lazy as BS let x = BS.readFile "somefile.txt" --some large file let z = ((reverse (BS.unpack x)) !! 2) --do stuff here I know bytestrings can be used to read large amounts of…
ArchHaskeller
  • 1,270
  • 1
  • 12
  • 28