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

A Stream can pull anything. #1757

Closed

Conversation

diesalbla
Copy link
Contributor

A Stream[F, O] is defined as a wrap on a FreeC[F, O, Unit]. The Unit type indicates that the "Result" of the FreeC computation that produces the stream has no relevant information: all that matters of the Stream is the output.

We can also express that idea by marking that return type as an Any, the top type, which is another way to indicate that no useful information can come off the Result of the inner FreeC. One benefit is that we do not need the spurious conversions of the FreeC with void, just to wrap it back into a Stream.

A `Stream[F, O]` is defined as a wrap on a `FreeC[F, O, Unit]`.
The Unit type indicates, in types, that the "Result" type of the FreeC
computation that would yield the stream is of no consequence:
a Stream is a complete FreeC on its own, and its result is of no matter.

We can also express that idea, in types, by marking that return type
as an `Any`, the top type, which is another way to indicate that no
useful information can come off the Result of the inner FreeC.
One benefit is that we do not need spurious conversions on the FreeC
object just to convert it back-and-forth a Stream: Any thing will do.

To avoid problems with the Any poly-kindness, and much like with the
INothing alias, we use a special IAny alias of Any for the types.
@diesalbla diesalbla changed the title A Stream can Pull anything: change Stream to FreeC[F, O, IAny] A Stream can Pull anything: Stream as FreeC[F, O, IAny] Jan 22, 2020
@diesalbla diesalbla changed the title A Stream can Pull anything: Stream as FreeC[F, O, IAny] A Stream can Pull anything: Stream as FreeC[F, O, Any] Jan 22, 2020
@diesalbla diesalbla changed the title A Stream can Pull anything: Stream as FreeC[F, O, Any] A Stream can pull anything. Jan 22, 2020
val _ = ev
new Stream(free.asInstanceOf[FreeC[F, O, Unit]])
}
def stream: Stream[F, O] = new Stream(free)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm generally 👎 on removing the R <:< Unit requirement here as requiring that evidence has exposed bugs where the remainder was not dealt with correctly.

/**
* Alias for `Any` which may work better with type inference.
*/
type IAny >: Any
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to go this way, I don't think we need IAny as scalac doesn't treat Any special from type inference perspective.

@mpilquist
Copy link
Member

mpilquist commented Jan 23, 2020

Not sure about this one. Would like to hear from other contributors. API-wise, I'm concerned about the ability to convert any pull to a stream, which seems like a regression considering we recently added the R <:<: Unit constraint (#1512). It's like the pull version of -Ywarn-value-discard. I'd like to hear more from other contributors though.

@SystemFw
Copy link
Collaborator

This is a torny issue in general (consider *> on one hand, and -Ywarn-value discard on the other).
Overall, I think I'm in favour of keeping R <:< Unit, because it really drives home the difference between O and R in Pull.

Also, I would only use Any when nothing else will do (e.g. in the implementation of Resource and IO) to really mean anything, because according to this argument, all uses of Unit could be replaced by Any (which in a way is the definition of value discarding, which I don't think is a good idea)

@diesalbla
Copy link
Contributor Author

I'm generally 👎 on removing the R <:< Unit requirement here as requiring that evidence has exposed bugs where the remainder was not dealt with correctly.

All right. That makes this PR no longer useful.

@diesalbla diesalbla closed this Jan 23, 2020
@diesalbla diesalbla deleted the stream_can_pull_anything branch August 20, 2020 16:18
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

Successfully merging this pull request may close these issues.

3 participants