Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6344817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:42:51+00:00 2026-05-24T20:42:51+00:00

I still don’t get how bytestrings work import qualified Data.ByteString.Lazy as BS let x

  • 0

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 data ,very quickly and efficiently. But unpacking a packing doesn’t make sense.

let z = readArray x 1 --can you read the bytestring like its a array?(something like this)

Can’t you just read the data in bytestring form without unpacking? or just unpack a segment of the data?

Could you explain how it all works?(Code examples)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:42:51+00:00Added an answer on May 24, 2026 at 8:42 pm

    But packing a unpacking doesn’t [make] sense.

    Well, it’s certainly wasteful.

    Can’t you just read the data in bytestring form without unpacking?

    • Do you mean operate on the data without converting it to another form? Sure you can. Exactly how depends on what you want to do. I’ve used FFI (and later, Data.Vector.Storable) to access the ByteString as a set of Word32‘s. You can pull out any individual Word8 naturally. I’m sure you’ve seen ByteString’s Haddock documents, but know that other packages consume bytestrings directly (ex: for communicating an image buffer with C code that is called via FFI).

    • Do you mean “operate on the data without using [Word8] or [Char]“? The binary, cereal, and other packages can be used to parse bytestrings into arbitrary types.

    or just unpack a segment of the data?

    Sure:

    import Data.ByteString as B
    
    getPortion n m = B.unpack . B.take n . B.drop m
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Something I still don't understand when performing an http-get request to the server is
I still don't quite get it, where to put images in rails 3.1, in
I guess I still don't get git as I'd hoped... I was creating a
After reading : this I still don't get it. in console: puts Category.joins(:posts) It
there is something i still don't get. for every class i declare there is
I've been reading for an hour now and still don't get what is going
I've read all the other threads but I still don't get why my apps
I've looked up the functions in the manual, but I still don't get this.
I still don't get the point of investing some coding time to add this
I've been reading all the questions on here but I still don't get it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.