on master help sign in
update array, add unfold, fix examples
commit5215f3f06dbb11a42109f2c3acc96a42115ebc27 authorHarendra Kumar <harendra.kumar@gmail.com> dateWed 6 Nov 2019, 02:38 (7 years ago) parent9bf84d4
1 file changed+27−20
README.md+27−20
README.md+27−20
@@ -361,42 +361,49 @@ documentation.
361361
362362## Arrays
363363
364−The `Streamly.Memory.Array` module provides mutable arrays. Arrays are the
365−computing duals of streams. Streams are good at sequential access, immutable
366−transformations of in-transit data whereas arrays are good at random access,
364+The `Streamly.Memory.Array` module provides immutable arrays. Arrays are the
365+computing duals of streams. Streams are good at sequential access and immutable
366+transformations of in-transit data whereas arrays are good at random access and
367367in-place transformations of buffered data. Unlike streams which are potentially
368368infinite, arrays are necessarily finite. Arrays can be used as an efficient
369369interface between streams and external storage systems like memory, files and
370370network. Streams and arrays complete each other to provide a general purpose
371371computing system. The design of streamly as a general purpose computing
372372framework is centered around these two fundamental aspects of computing and
373−storage.
373+storage.
374374
375−Arrays in streamly use pinned memory outside GC and therefore avoid any GC
376−overhead for the storage in arrays. `ByteString` data type from the
377−`bytestring` package and the `Text` data type from the `text` package are just
378−special cases of arrays. `ByteString` is equivalent to `Array Word8` and `Text`
379−is equivalent to a `utf16` encoded `Array Word8`. All the bytestring and text
380−operations can be performed on arrays with equivalent or better performance by
381−converting them to and from streams.
375+`Streamly.Memory.Array` uses pinned memory outside GC and therefore avoid any
376+GC overhead for the storage in arrays. Streamly allows efficient
377+transformations over arrays using streams. It uses arrays to transfer data to
378+and from the operating system and to store data in memory.
382379
383380## Folds
384381
385−`Streamly.Data.Fold` module provides composable left folds. A `Fold` is a consumer
386−of a stream. Folds can be used to fold a stream. Folds can be composed in many
387−ways, a stream can be distributed to multiple folds, or it can be partitioned
388−across multiple folds, or demultiplexed over multiple folds, or unzipped to two
389−folds. We can also use folds to fold segments of stream generating a stream of
390−the folded results.
382+Folds are consumers of streams. `Streamly.Data.Fold` module provides a `Fold`
383+type that represents a `foldl'`. Such folds can be efficiently composed
384+allowing the compiler to perform stream fusion and therefore implement high
385+performance combinators for consuming streams. A stream can be distributed to
386+multiple folds, or it can be partitioned across multiple folds, or
387+demultiplexed over multiple folds, or unzipped to two folds. We can also use
388+folds to fold segments of stream generating a stream of the folded results.
391389
392390If you are familiar with the `foldl` library, these are the same composable
393391left folds but simpler and better integrated with streamly, and with many more
394392powerful ways of composing and applying them.
395393
394+## Unfolds
395+
396+Unfolds are duals of folds. Folds help us compose consumers of streams
397+efficiently and unfolds help us compose producers of streams efficiently.
398+`Streamly.Data.Unfold` provides an `Unfold` type that represents an `unfoldr`
399+or a stream generator. Such generators can be combined together efficiently
400+allowing the compiler to perform stream fusion and implement high performance
401+stream merging combinators.
402+
396403## File IO
397404
398405The following code snippets implement some common Unix command line utilities
399−using streamly. You can compile these with `ghc -O2 -fspec-constr-recursive=10
406+using streamly. You can compile these with `ghc -O2 -fspec-constr-recursive=16
400407-fmax-worker-args=16` and compare the performance with regular GNU coreutils
401408available on your system. Though many of these are not most optimal solutions
402409to keep them short and elegant. Source file
@@ -431,14 +438,14 @@ withArg2 f = do
431438### cat
432439
433440``` haskell
434−cat = S.fold (FH.writeArrays stdout) . S.unfold FH.readArrays
441+cat = S.fold (FH.writeChunks stdout) . S.unfold FH.readChunks
435442main = withArg cat
436443```
437444
438445### cp
439446
440447``` haskell
441−cp src dst = S.fold (FH.writeArrays dst) $ S.unfold FH.readArrays src
448+cp src dst = S.fold (FH.writeChunks dst) $ S.unfold FH.readChunks src
442449main = withArg2 cp
443450```
444451