Haskell Language Learning Note (ByteString Text)

Source: Internet
Author: User

Data.bytestring

String is a synonym for [Char], and there is a performance problem with the inertia of list on use.
When working with large binary files, you can use ByteString instead of String.
The ByteString contains the Lazy module Data.ByteString.Lazy and the Strict module data.bytestring.
Where the Lazy module uses chunks (64K data blocks) internally.

Prelude> import qualified Data.ByteString.Lazy as BPrelude B> import qualified Data.ByteString as SPrelude B S> B.pack [99,97,110]"can"Prelude B S> B.fromChunks [S.pack [40,41,42], S.pack [43,44,45], S.pack [46,47,48]]"()*+,-./0"Prelude B S> B.cons 85 $ B.pack [80,81,82,84]"UPQRT"Prelude B S> foldr B.cons' B.empty [50..60] "23456789:;<"
Data.text

When working with large text files, you can use text instead of String.
Text is a Unicode-friendly string type.
Text contains the Lazy module Data.Text.Lazy and Strict module DATA.TEXT.
Where the chunks is used internally by the Lazy module.

Prelude> import qualified Data.Text.Lazy as TPrelude T> :t T.pack "abc"T.pack "abc" :: T.TextPrelude T> T.replace (T.pack "a") (T.pack "b") (T.pack "aXaXaX")"bXbXbX"Prelude T> T.splitOn (T.pack "a") (T.pack "aXaXaX")["","X","X","X"]

Haskell Language Learning Note (ByteString Text)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.