Skip to content

remove Ops classes - #1114

Merged
fwbrasil merged 1 commit into
mainfrom
remove-ops-classes
Mar 29, 2025
Merged

fwbrasil merged 1 commit into
mainfrom
remove-ops-classes

Conversation

@fwbrasil

@fwbrasil fwbrasil commented Mar 28, 2025 •

Copy link
Copy Markdown
Collaborator

Problem

We used to use Ops classes to encode methods with multiple type parameter groups. The latest versions of the compiler include the new clause interleaving feature that provides a similar mechanism. I was initially reluctant to adopt it because I thought it could make it harder for people reading the codebase to understand the method signatures but there are important drawbacks with the current Ops classes:

  • The scaladoc generation isn't great because there's the op builder method indirection
  • Use of pipe with methods using Ops classes requires an explicit function. For instance, a.pipe(Abort.run) doesn't compile but a.pipe(Abort.run(_)) does.
  • The noise of the Ops classes makes the code less readable

Solution

Migrate the all Ops classes to clause interleaving. To have some consistency, I used the Frame as the implicit to separate type parameter groups since the compiler currently requires parameters between type parameter groups.

Notes

  • There are no changes to the method bodies nor scaladocs.

fr: Frame
): B < (Abort[Nothing] & S & S1) =
Abort.fold(onSuccess, onFail)(effect)
Abort.fold[E](onSuccess, onFail)(effect)

@fwbrasil fwbrasil Mar 28, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The explicit type parameter here shouldn't be necessary. It seems the issue is the use of Reducible. Considering that Abort[Nothing] is included in IO and derived effects, I think we can remove Reducible. It'll simplify type inference and improve compilation errors for type mismatches. The error messages with Reducible can be cryptic. I'm planning to follow up on that. Let me know if you have concerns @hearnadam @johnhungerford

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

When you say we can remove it, do you mean entirely or just from Abort? Env still uses Reducible, correct?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point! I forgot about Env. It'd be only the Abort-related ones

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No luck removing Reducible from Abort. We need to be able to fully handle Abort in the APIs that handle panics anyway

@fwbrasil
fwbrasil merged commit fd98b54 into main Mar 29, 2025
@fwbrasil
fwbrasil deleted the remove-ops-classes branch March 29, 2025 04:37
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