Commit Graph

823 Commits

Author SHA1 Message Date
Harendra Kumar
0133e7424f
Merge pull request #151 from composewell/unstream-safe
Make unStream use rstState, making it safer.
2018-12-29 16:20:11 +05:30
Harendra Kumar
d01942d9dd Add applicative benchmarks
Specialize asyncly/wAsyncly/aheadly applicative instances
2018-12-29 15:23:47 +05:30
Harendra Kumar
a4fa2d3974 make some ops INLINE(ABLE)
uncons/zipAsyncWith(M)
2018-12-29 13:39:41 +05:30
Harendra Kumar
25cb5da69b Use rewrite rules to simplify sepcialized code
improved the performance of "drop" operations by 2x
2018-12-29 13:33:36 +05:30
Harendra Kumar
831113b513 recover streamK "drop" performance by using unShare only once
Note that the drop in "mapM" performance in concurrent benchmarks is due to a
benchmark change. We now use the parallel verison of unfoldrM instead of serial
version to generate the stream.
2018-12-28 19:12:00 +05:30
Harendra Kumar
ede29df8d0 specialize the typeclass instances to recover performance 2018-12-28 12:25:52 +05:30
Harendra Kumar
c0420503a1 Fix performance for some ops
especially map/mapM for StreamK and uncons/tail for StreamD
2018-12-27 18:04:45 +05:30
Harendra Kumar
9c8a7504fa Add mapM_ benchmark, add build/augment 2018-12-27 13:59:25 +05:30
Harendra Kumar
a30ef3eef9 Add a nano benchmark for unfoldr, fix dev benchmarks 2018-12-27 00:52:33 +05:30
Harendra Kumar
57fad213a0 Rename the StreamK and StreamD Type modules 2018-12-26 17:07:24 +05:30
Harendra Kumar
c175cddef5 Use bindWith to implement all the binds 2018-12-26 16:59:35 +05:30
Harendra Kumar
0a2755a48c Change the order of foldStream arguments
To make it consistent with regular fold function conventions.
2018-12-26 16:31:38 +05:30
Harendra Kumar
90844f990b Fix a concatMap performance issue 2018-12-26 13:24:24 +05:30
Harendra Kumar
24375dc077 move the callback construction APIs to core module 2018-12-26 13:13:14 +05:30
Harendra Kumar
0258d77a49 clarify foldr and foldl docs 2018-12-26 13:13:14 +05:30
Harendra Kumar
2ba5f01d8c rename unstream et. al. and make them polymorphic
rename:
  unStream to foldStream
  unStreamShared to foldStreamShared
  unStreamSVar to foldStreamSVar

Change the order of arguments to match the standard fold convention.
Make them polymorphic so as to make them more convenient to use without having
to always use fromStream/toStream.

TBD: check performance impact
2018-12-11 20:01:02 +05:30
Harendra Kumar
183325ec73 factor out the StreamK type in a separate file 2018-12-10 23:52:01 +05:30
Harendra Kumar
e08ff863f6 Move the StreamD Type in a separate module 2018-12-10 22:55:08 +05:30
Harendra Kumar
315abcf410 Fix some state sharing/clearing safety issues
1. removed redundant rstState from mergeAsyncBy and mergeByS
2. renamed rstState to adaptState, as it is now used only coerce one state type to
   another.
3. renamed isolateStream to unShare
4. made StreamD as well safer by clearing the SVar sharing during pattern match
2018-12-10 21:18:07 +05:30
Pranay Sashank
769ce84f8f Use unStream with defState, instead of unStreamShared. 2018-12-10 13:19:04 +05:30
Pranay Sashank
c1b1f9224f Fix improper usage of unStream together with rstState. 2018-12-10 13:19:04 +05:30
Pranay Sashank
924856bbbe Make the default unStream safe, #96.
1) Hide the `Stream` constructor, use `mkStream` instead.
2) Change `unStream` to use `rstState`.
3) Use `unStreamShared` to share the `SVar`.
4) Remove `unStreamIsolated`, use `unStream` instead.
5) Change all `unStream m (rstState st)` to `unStream m st`
6) Change all `unStream m st` to `unStreamShared m st`
2018-12-10 13:19:04 +05:30
Pranay Sashank
7c2b9b7c8a Refactor unstreamShared to unStreamShared. 2018-12-10 13:17:11 +05:30
Harendra Kumar
ffab417ac4 remove leftover comment 2018-12-10 08:57:57 +05:30
Harendra Kumar
0113d3c16e
Merge pull request #138 from composewell/prelude-ops
Prelude functions
2018-12-10 08:51:46 +05:30
Harendra Kumar
dbc1956141 Review of #138 (Prelude functions) and other changes
APIs
----

Removed:
  merge
  lazy left scans: scanl, scanlM, scanl1, scanl1M

Renamed:
  generate and generateM renamed to fromIndices and fromIndicesM

Added:
  replicate
  mergeByM, mergeAsyncBy, mergeAsyncByM
  `intFrom`, `intFromTo`, `intFromThen`, `intFromThenTo`,
  `intFromStep`, `fracFrom`, `fracFromThen`, `fracFromThenTo`,
  `numFromStep`

Added StreamD version of replicateM and a rewrite rule for replicateMSerial.

Added but not exposed:
  postscanl and prescanl ops

Rewrote mergeByS in StreamK, simplified quite a bit and got some perf
improvement too.

Added @since notations to new APIs.

Fixed lines exceeding 80 columns.

Tests
-----

Added tests for the new enumeration APIs.
Improved some tests by generating values randomly using quickcheck forAll. We
can improve more tests similarly.

Removed some redundant transformOps tests.

reorganized test code in groups so as to keep similar functionality together
and added header lines so that we can find relevant code easily.

Benchmarks
----------

Added benchmarks for enumeration primitives added above. Added benchmarks for
scan and fold mixed ops. Added benchmark for concatMap. Fixed foldr and foldrM
benchmarks to use a (+) operation instead of a list operation for fair
comparision with other folds.

Kept only one benchmark each for deleteBy, insertBy, isPrefixOf and
isSubsequenceOf.

Documentation
-------------

Updated documentation, added examples for the new primitives as well as many
old ones. Especially the documentation of folds and scans was rewritten.

Reordered and re-organized the groups of APIs in the doc.

Refactoring
-----------

Some related and urelated refactoring.

Hlint
-----

Fixed some hlint hints introduced recently.

TBD
---

Some APIs need concurrent versions. I have added "XXX" notes for those.
Some more tests have to be added.
Some more benchmarks have to be added.
2018-12-09 19:39:37 +05:30
Pranay Sashank
de083af8e7 Group merging and subsequences benchmarks. 2018-11-22 10:17:15 +05:30
Pranay Sashank
04907e303e Remove splitAt. 2018-11-22 10:07:12 +05:30
Pranay Sashank
5fc469ad77 Add uniq, indexed, indexedR. 2018-11-22 10:03:46 +05:30
Pranay Sashank
5bb0a49a9a Add concatMap, concatMapM, generateM, generate, findM to Prelude. 2018-11-22 10:03:46 +05:30
Pranay Sashank
b2c86b1094 Add replicate. 2018-11-22 10:03:00 +05:30
Pranay Sashank
9ccee33329 Use substream functions from StreamD not the imported Stream. 2018-11-22 10:03:00 +05:30
Pranay Sashank
dbcf5363e8 Add isPrefixOf, isSubsequenceOf, stripPrefix to Prelude, StreamD. 2018-11-22 10:03:00 +05:30
Pranay Sashank
55e582efaf INLINE insert and delete in benchmarks. 2018-11-22 10:02:04 +05:30
Pranay Sashank
acc38719fd Fixed insertBy to use correct state. Add deleteBy.
- Benchmarks show very poor performance of insertBy and
deleteBy compared to StreamK. Should be improved in StreamD.
2018-11-22 10:02:04 +05:30
Pranay Sashank
7f82af409c Add scanl1, scanl1M, scanl1', scanl1M', scanl, scanlM to StreamD. 2018-11-22 10:00:38 +05:30
Pranay Sashank
3186bd283f Add maximumBy and minimumBy. 2018-11-22 09:56:48 +05:30
Harendra Kumar
5e38a5715f simplify mergeBy implementation 2018-11-22 09:55:05 +05:30
Pranay Sashank
5cc6933cdb Add (!!), insertBy, merge, mergeBy, splitAt, the to Prelude.
1) Add foldr1, findIndices, lookup, find, sequence functions
in StreamD, earlier they were present only in StreamK.
2) Change the above functions to use S. in Prelude instead
of K. .
3) Add tests for (!!), insertBy, splitAt, the.
2018-11-22 09:53:40 +05:30
Harendra Kumar
6daacf0d49 Add foldl' benchmark for pure streams to cmp with Foldable 2018-11-19 12:44:53 +05:30
Harendra Kumar
11d8d6dc66 Fix foldable/traversable instances
1) Define the instances manually instead of deriving. Deriving picks up
incorrect implementations of methods that have been redefined in the newtypes.

2) Fix the Traversable instance.

3) Define the instances only for Serial stream types. Other streams cannot be
instantiated for Foldable monads.

4) Add test cases

5) add benchmarks
2018-11-19 12:13:33 +05:30
Harendra Kumar
9e114ffa2f define IsList instances for GHC 8.0 and below 2018-11-19 08:55:20 +05:30
Harendra Kumar
0839d4f6f1 Add the ZipList type and more tests for pure lists 2018-11-19 08:55:20 +05:30
Harendra Kumar
ee0c73b22c Add List and String types 2018-11-16 14:39:26 +05:30
Harendra Kumar
c28043f48a Add pure stream (list) instances
Pure streams are streams with Identity as the base monad.
Added Eq/Ord/Read/Show/IsString/IsList instances for pure streams.
2018-11-16 14:39:26 +05:30
Harendra Kumar
7527247381
Merge pull request #124 from Abhiroop/foldable-traversable
Add Foldable and Traversable instances for StreamD and StreamK
2018-11-16 13:59:29 +05:30
Harendra Kumar
2228ab0eb5 Add references to async 2018-11-10 03:37:16 +05:30
Harendra Kumar
4b75877900 Fix example code in Prelude 2018-11-10 03:37:03 +05:30
Harendra Kumar
4df1a938e4 change the INLINE phase of scanlM' to NORMAL 2018-11-06 07:02:04 +05:30
Harendra Kumar
adf667a5ea use -fspec-constr-recursive=10 flag for benchmarks 2018-11-06 06:43:43 +05:30