Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should effectful streams *ever* be passed as arguments to more than one function? #77

Open
danidiaz opened this issue May 15, 2019 · 4 comments

Comments

@danidiaz
Copy link
Contributor

Let's say I have an IO-based Stream. Is it ever a good idea to pass the same Stream value to two different functions? As opposed of passing it to a function that returns a new Stream, or to a function that eliminates the Stream and brings us back to the base monad.

If the answer is no, perhaps we should document it, because newcomers to the library might not be aware of the need to follow that discipline (linear types could make it a compile-time restriction, but we don't have them in Haskell yet).

Is there any counterexample to this?

@treeowl
Copy link
Contributor

treeowl commented May 15, 2019

@treeowl
Copy link
Contributor

treeowl commented May 15, 2019

Certainly a pure stream can be reused, regardless of the monad it's embedded in. Aside from that, I think any valid uses in IO would be fairly brittle and better expressed in other ways. For "pure" monads like [] and Maybe, it's harder to say.

@andrewthad
Copy link
Contributor

I would venture to say that it is never good to consume an IO-based stream in a non-linear fashion.

@facundominguez
Copy link

facundominguez commented Apr 9, 2020

There's an argument for using linear types for streams here.

Despite the emphasis on effects, if pure streams were used in non-linear fashion, there would be little guarantees that the contents of the streams aren't retained in memory, defeating the purpose of "streaming".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants