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

Aborts-like encoding for Envs #298

Merged
merged 4 commits into from
Apr 30, 2024
Merged

Aborts-like encoding for Envs #298

merged 4 commits into from
Apr 30, 2024

Conversation

fwbrasil
Copy link
Collaborator

Follows the new Aborts approach favoring companion object methods.

kyo-core/shared/src/main/scala/kyo/envs.scala Outdated Show resolved Hide resolved
kyo-core/shared/src/main/scala/kyo/envs.scala Outdated Show resolved Hide resolved
Envs[Int].run(0)(
Aborts.run[Ex1](Aborts.catching[Ex1](test(Envs[Int].get)))
Envs.run(0)(
Aborts.run[Ex1](Aborts.catching[Ex1](test(Envs.get[Int])))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given the parameter includes the type: def test(v: Int < Env[Int]
Can you try invoking it like: test(Envs.get)? not that this is particularly safe...

Copy link
Collaborator Author

@fwbrasil fwbrasil Apr 30, 2024

Choose a reason for hiding this comment

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

yep! That works too. Why do you say it could be unsafe?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Type unsafe 🙂 - inference could change depending on how the function is defined. Obviously not a problem with Kyo's encoding.

It's likely not a concern for most users, as they should rarely define functions where the result type is generic.

eg

type Pending = Envs[Float] & Envs[Double]
def myFunc[T](effect: T < Pending) = effect.map(_ / 2)

val result: ??? = myFunc(Envs.get)

Determinism in the Scala compiler is generally good, but I generally prefer not to take changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tested this and it's actually unsafe as you suspected. It's not much about the method inference but Scala infers a type intersection as the environment type, which fails when handling the effect. I think we'll need to add a constraint similar to Flat to validate that the type is not an intersection. Another option is using Tag to check types during handling but that's too expensive.

I added a couple pending tests because I think this doesn't seem a blocker.

kyo-core/shared/src/main/scala/kyo/envs.scala Outdated Show resolved Hide resolved
@fwbrasil fwbrasil merged commit 74900ad into main Apr 30, 2024
3 checks passed
@fwbrasil fwbrasil deleted the new-envs-encoding branch April 30, 2024 03:56
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.

2 participants