streamly icon indicating copy to clipboard operation
streamly copied to clipboard

MonadPlus instances

Open kirelagin opened this issue 5 years ago • 3 comments
trafficstars

Currently, streamly does not provide MonadPlus instances for its transformers. (#18, #20, #60)

However, there is a well-known pattern for implementing library-agnostic stream sources (http://www.haskellforall.com/2014/11/how-to-build-library-agnostic-streaming.html) and it relies on having a MonadPlus instance. So, it would be highly desirable to pick some reasonable semantics (compatible with what other libraries implement) and provide MonadPlus instances to make streamly usable with this pattern.

kirelagin avatar Jun 19 '20 17:06 kirelagin

Thanks for raising the issue and for the reference.

Implementing Alternative and MonadPlus is in the plan, we have not been able to get to it yet.

harendra-kumar avatar Jun 22 '20 09:06 harendra-kumar

Implementing Alternative and MonadPlus is in the plan, we have not been able to get to it yet.

I would love to see an Alternative instance for SerialT. As far as I can tell you already have the machinery in place. I added the following trivial (orphan) instance to my code:

instance (Monad m) => Alternative (SerialT m) where
  (<|>) = mappend
  empty = mempty

This allowed me to convert some code that was written for LogicT to SerialT by just changing the type signatures (I wasn't relying on LogicT's fairness anywhere). I could have gotten by without that instance by writing my own replacement for Control.Monad.guard in terms of Monoid/Monad as well but having the instance may come in handy later.

dagit avatar Jun 23 '21 17:06 dagit

@dagit Noted. We had an alternative instance once but it was removed later because we wanted to think about all the stream types and keep it consistent across all. We have been busy with getting other fundamental things right, but we will get back to it.

Have you seen https://github.com/composewell/ds-kanren? It uses streamly in place of logict with fairness (using wSerial).

harendra-kumar avatar Jun 24 '21 07:06 harendra-kumar