bytestring

Bytestring linking in ghc

我只是一个虾纸丫 提交于 2019-12-05 06:30:36
Consider the following simple code: import Crypto.Hash.SHA1 (hashlazy) import qualified Data.ByteString as BS main = return () I installed cabal install --global bytestring and then I obtain (on a newly installed Ubuntu 12.04 machine using ghc 7.4.1): GHCi runtime linker: fatal error: I found a duplicate definition for symbol fps_minimum whilst processing object file /usr/local/lib/bytestring-0.10.0.1/ghc-7.4.1/HSbytestring-0.10.0.1.o This could be caused by: * Loading two different object files which export the same symbol * Specifying the same object file twice on the GHCi command line * An

In Haskell, will calling length on a Lazy ByteString force the entire string into memory?

拥有回忆 提交于 2019-12-05 03:41:44
I am reading a large data stream using lazy bytestrings, and want to know if at least X more bytes is available while parsing it. That is, I want to know if the bytestring is at least X bytes long. Will calling length on it result in the entire stream getting loaded, hence defeating the purpose of using the lazy bytestring? If yes, then the followup would be: How to tell if it has at least X bytes without loading the entire stream? EDIT: Originally I asked in the context of reading files but understand that there are better ways to determine filesize. Te ultimate solution I need however should

Efficient bitstreams in Haskell

情到浓时终转凉″ 提交于 2019-12-04 16:48:50
问题 In an ongoing endeavour to efficiently fiddle with bits (e.g. see this SO question) the newest challenge is the efficient streaming and consumption of bits. As a first simple task I choose to find the longest sequence of identical bits in a bitstream generated by /dev/urandom . A typical incantation would be head -c 1000000 </dev/urandom | my-exe . The actual goal is to stream bits and decode an Elias gamma code, for example, i.e. codes that are not chunks of bytes or multiples thereof. For

Matching bytestrings in Parsec

夙愿已清 提交于 2019-12-04 09:26:56
I am currently trying to use the Full CSV Parser presented in Real World Haskell . In order to I tried to modify the code to use ByteString instead of String , but there is a string combinator which just works with String . Is there a Parsec combinator similar to string that works with ByteString , without having to do conversions back and forth? I've seen there is an alternative parser that handles ByteString : attoparsec , but I would prefer to stick with Parsec, since I'm just learning how to use it. I'm assuming you're starting with something like import Prelude hiding (getContents,

Frequency of characters

血红的双手。 提交于 2019-12-04 07:56:09
I am trying to find frequency of characters in file using Haskell . I want to be able to handle files ~500MB size. What I've tried till now It does the job but is a bit slow as it parses the file 256 times calculateFrequency :: L.ByteString -> [(Word8, Int64)] calculateFrequency f = foldl (\acc x -> (x, L.count x f):acc) [] [255, 254.. 0] I have also tried using Data.Map but the program runs out of memory (in ghc interpreter). import qualified Data.ByteString.Lazy as L import qualified Data.Map as M calculateFrequency' :: L.ByteString -> [(Word8, Int64)] calculateFrequency' xs = M.toList $ L

Haskell How to Create a Word8?

。_饼干妹妹 提交于 2019-12-04 02:20:54
I want to write a simple function which splits a ByteString into [ByteString] using '\n' as the delimiter. My attempt: import Data.ByteString listize :: ByteString -> [ByteString] listize xs = Data.ByteString.splitWith (=='\n') xs This throws an error because '\n' is a Char rather than a Word8 , which is what Data.ByteString.splitWith is expecting. How do I turn this simple character into a Word8 that ByteString will play with? You could just use the numeric literal 10 , but if you want to convert the character literal you can use fromIntegral (ord '\n') (the fromIntegral is required to

Efficient bitstreams in Haskell

情到浓时终转凉″ 提交于 2019-12-03 10:59:19
In an ongoing endeavour to efficiently fiddle with bits (e.g. see this SO question ) the newest challenge is the efficient streaming and consumption of bits. As a first simple task I choose to find the longest sequence of identical bits in a bitstream generated by /dev/urandom . A typical incantation would be head -c 1000000 </dev/urandom | my-exe . The actual goal is to stream bits and decode an Elias gamma code , for example, i.e. codes that are not chunks of bytes or multiples thereof. For such codes of variable length it is nice to have the take , takeWhile , group , etc. language for list

Reading large file in haskell?

て烟熏妆下的殇ゞ 提交于 2019-12-03 07:01:18
问题 i've been trying to read a large file in haskell. I need to compress it using a custom algorithm for a university project. Everything works fine untill i start to compress big files. I extracted what was going wrong out of my program, and i expose it here in the form of a "Hello big file": import System import qualified Data.ByteString.Lazy as BL import Data.Word fold_tailrec :: (a -> b -> a) -> a -> [b] -> a fold_tailrec _ acc [] = acc fold_tailrec foldFun acc (x : xs) = fold_tailrec foldFun

When do I use ByteString and when do I not?

牧云@^-^@ 提交于 2019-12-03 01:19:53
I've been making rather poor attempts at the PRIME1 problem on SPOJ. I discovered using that using ByteString really helped performance for reading in the problem text. However, using ByteString to write out the results is actually slightly slower than using Prelude functions. I'm trying to figure out if I'm doing it wrong, or if this is expected. I've conducted profiling and timing using (putStrLn.show) and the ByteString equivalents three different ways: I test each candidate to see if it is prime. If so, I add it to a list and write it out with (putStrLn . show) I make a list of all primes

How do I convert a Python 3 byte-string variable into a regular string?

佐手、 提交于 2019-12-03 01:18:11
问题 I have read in an XML email attachment with bytes_string=part.get_payload(decode=False) The payload comes in as a byte string, as my variable name suggests. I am trying to use the recommended Python 3 approach to turn this string into a usable string that I can manipulate. The example shows: str(b'abc','utf-8') How can I apply the b (bytes) keyword argument to my variable bytes_string and use the recommended approach? The way I tried doesn't work: str(bbytes_string, 'utf-8') 回答1: You had it