Nested newtype wrapper vs Stream/StreamK Applicative and Monad instances

Open
#3,115 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
haskell
Domain
backend

Research direction

Read the Stream and StreamK newtype wrappers and their Applicative, Monad, Semigroup, and MonadPlus instances in streamly-core. Compare the performance implications of bind association and append, and assess whether adding these instances or using explicit concatFor operations best addresses the concerns in the issue; the issue does not name files or tests, so first locate the relevant definitions.

Written by the indexing model from the issue text.

Description

aspect:api

Do we want MonadState, MonadReader etc instances in future for this type? If so we will need to depend on mtl - streamly-core currently does not depend on mtl. Or we will have to move these types to streamly instead of streamly-core.

Another option is - instead of using newtype wrappers we can merge these instances with the Stream and StreamK types. We can use the concatFor (bind) operations directly instead of Monad instance, but a Monad instance could be useful where it is used implicitly - e.g. MonadComprehensions. We did not add a Monad instance earlier to avoid the misuse of the monad instance. What are the potential misuses?

  • We must not have Semigroup and MonadPlus instances for Stream type so it cannot be appended, append has quadratic complexity for Stream, though we can have it for StreamK which has a linear append.
  • Left associating the binds in a chain could hurt performance - they should be explicitly right associated
  • Applicative should be preferred as it would be much faster - maybe we can just provide an Applicative and leave the monad type composition to explicit concatFor (bind) operations.
Dominant language
Haskell
Stars
926
Forks
71
Avg merge
6h 49m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from composewell/streamly

All issues in composewell/streamly

Similar issues

More Haskell issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.