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

Better MonadError handling to avoid nesting ExceptT in modifyError #431

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

carbolymer
Copy link
Contributor

@carbolymer carbolymer commented Jan 17, 2024

Changelog

- description: |
    Better `MonadError` handling to avoid nesting `ExceptT` in `modifyError`
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
   - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
   - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

This PR addresses problems with modifyError from mtl noticed by @newhoggy. Briefly speaking, mtl's modifyError nests MonadError e m in the ExceptT. Therefore using modifyError multiple times produces a type similar to:

ExceptT e1 (ExceptT e2 (ExceptT e3 m a))

This is a problem, because nested monads will have a negative performance impact.

There are two ways to fix this:

  1. (this PR's approach) Use MonadTrans constraint in addition to MonadError.
  2. Use concrete monad for errors: (MonadIO m, ...) => ExceptT e m a everywhere instead of MonadError, use other monad constraints on m.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@carbolymer carbolymer force-pushed the mgalazyn/fix/better-monad-error-mapping branch 6 times, most recently from 1df4c90 to d0de00e Compare January 18, 2024 11:01
@carbolymer carbolymer changed the title Mgalazyn/fix/better monad error mapping Better MonadError handling to avoid nesting ExceptT in modifyError Jan 18, 2024
@carbolymer carbolymer force-pushed the mgalazyn/fix/better-monad-error-mapping branch from d0de00e to ea1b77b Compare January 18, 2024 11:23
@carbolymer carbolymer marked this pull request as ready for review January 18, 2024 12:10
@carbolymer carbolymer force-pushed the mgalazyn/fix/better-monad-error-mapping branch 3 times, most recently from b71953c to 10a2734 Compare January 18, 2024 13:32
@carbolymer carbolymer force-pushed the mgalazyn/fix/better-monad-error-mapping branch from 10a2734 to 586241a Compare January 18, 2024 13:35
@carbolymer carbolymer enabled auto-merge January 18, 2024 15:23
@carbolymer carbolymer added this pull request to the merge queue Jan 18, 2024
Merged via the queue into main with commit 83899dc Jan 18, 2024
18 checks passed
@carbolymer carbolymer deleted the mgalazyn/fix/better-monad-error-mapping branch January 18, 2024 21:28
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