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

Pull's public api is unsound #3484

Open
ValdemarGr opened this issue Sep 28, 2024 · 0 comments
Open

Pull's public api is unsound #3484

ValdemarGr opened this issue Sep 28, 2024 · 0 comments
Labels

Comments

@ValdemarGr
Copy link
Contributor

ValdemarGr commented Sep 28, 2024

Because of Translate we may only G ~> F, not F ~> G. However GetScope and any operator that uses GetScope is subject to a soundness hole since:

  • Scope is allocated in the initial F.
  • Scope cannot have mapK since it must be invariant in F (acquisition of child resources).

Here is an example that throws a class cast exception.

I have been looking at it for a while and I can't see any other road to a sound structure than to require F ~> G if any interaction with the open resources in necessary.

The good news is that either more stream programs can be expressed with F ~> G or at least the current semantics can be retained explicitly.

new FunctionK[F, G] {
  def apply[A](fa: F[A]): G[A] = throw new ClassCastException("Oh no, couldn't go from F to G")
}

Assuming the api is used without throwing of exceptions, a bi-directional Translate allows Scope to be exposed (or at-least a subset of Scope's operators).

As of now, the only part of the api which is exposed and subject to this issue is lease. Fortunately lease doesn't invoke any other effects than ones in Scope, so any lossy F ~> G is completely fine, say EitherT[F, String, *] ~> F. Maybe a typeclass to represent non-structure preserving translations to make the G ~> F derivable for most cases?

Another direction could be to ensure that any Pull that is built on GetScope is non-translatable. Although this might require an extra type parameter to Pull and consequently Stream unfortunately.

@ValdemarGr ValdemarGr added the bug label Sep 28, 2024
@ValdemarGr ValdemarGr changed the title Pull's public api is unsound Pull's public api is unsound Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant