polysemy-plugin
Disambiguate obvious uses of effects.
https://github.com/polysemy-research/polysemy#readme
LTS Haskell 23.1: | 0.4.5.2@rev:1 |
Stackage Nightly 2024-12-26: | 0.4.5.2@rev:1 |
Latest on Hackage: | 0.4.5.2@rev:1 |
polysemy-plugin-0.4.5.2@sha256:93b7591b6e96dc0c572872af8aa12168980201c847a9e245cf1225a26ce7e4d9,3293
Module documentation for 0.4.5.2
polysemy-plugin
Dedication
It doesn’t matter how beautiful your theory is, it doesn’t matter how smart you are. If it doesn’t agree with experiment, it’s wrong.
Richard Feynman
Overview
A typechecker plugin that can disambiguate “obvious” uses of effects in
polysemy
.
Example
Consider the following program:
foo :: Member (State Int) r => Sem r ()
foo = put 10
What does this program do? Any human will tell you that it changes the state of
the Int
to 10, which is clearly what’s meant.
Unfortunately, polysemy
can’t work this out on its own. Its reasoning is
“maybe you wanted to change some other State
effect which is also a Num
,
but you just forgot to add a Member
constraint for it.”
This is obviously insane, but it’s the way the cookie crumbles.
polysemy-plugin
is a typechecker plugin which will disambiguate the above
program (and others) so the compiler will do what you want.
Usage
Add the following line to your package configuration:
ghc-options: -fplugin=Polysemy.Plugin
Limitations
The polysemy-plugin
will only disambiguate effects if there is exactly one
relevant constraint in scope. For example, it will not disambiguate the
following program:
bar :: Members '[ State Int
, State Double
] r => Sem r ()
bar = put 10
because it is now unclear whether you’re attempting to set the Int
or the
Double
. Instead, you can manually write a type application in this case.
bar :: Members '[ State Int
, State Double
] r => Sem r ()
bar = put @Int 10
Acknowledgments
This plugin is copied almost verbatim from simple-effects
.
Changes
Changelog for polysemy-plugin
Unreleased
0.4.5.0 (2023-04-09)
Other Changes
- Support GHC 9.6
0.4.4.0 (2022-12-27)
- Support GHC 9.4
0.4.3.1 (2022-07-11)
- Add a missing pattern match that was hit by a user.
0.4.3.0 (2021-11-23)
- Support GHC 9.2.1
- Fix a regression that prevented disambiguation in some cases.
0.4.2.0 (2021-11-16)
- Support for
polysemy-1.7.0.0
0.4.1.0 (2021-10-22)
- The plugin can now use instances in scope to help solve ambiguous type variables.
0.4.0.0 (2021-07-12)
- Support GHC 9.0.1
0.3.0.0 (2021-03-30)
Breaking Changes
- Dropped support for GHC 8.4
0.2.5.2 (2020-11-01)
- Fixed crashes stemming from unused optimization passes (#382)
0.2.5.1 (2020-09-15)
- The plugin now works on GHC 8.10 (thanks to @googleson78)
0.2.5.0 (2020-02-14)
- Updated the lower bounds to
polysemy-1.3.0.0
because of changes topolysemy
internals - Updated the test suite to test against
polysemy-1.3.0.0
.
0.2.4.0 (2019-10-29)
- The plugin now works on GHC 8.8.1 (thanks to @googleson78 and @sevanspowell)
- Improved error messages for when you forgot to include
polysemy
itself
0.2.3.0 (2019-09-04)
- The plugin will now choose between given effects based on the ability to unify them. This makes it possible for disambiguation to kick in even when using multiple instances of the same effect with different type variables, as long as type annotations/applications are used to target a specific instance.
- Updated the test suite to test against
polysemy-1.2.0.0
.
0.2.2.0 (2019-07-04)
- The plugin will now prevent some false-positives in
polysemy
’s error messages - Updated the lower bounds to
polysemy-0.6.0.0
0.2.1.1 (2019-06-26)
- Updated the test suite to test against
polysemy-0.5.0.0
0.2.1.0 (2019-06-14)
- Greatly improved the plugin’s ability to unify polymorphic types when running interpreters.
0.2.0.3 (2019-06-13)
- Fixed a bug where the plugin could (incorrectly) loop indefinitely attempting to solve some constraints.
- Changed the lower-bound of
inspection-testing
to allow Cabal users to successfully run the test-suite.
0.2.0.2 (2019-06-09)
- Fixed a bug where the plugin wouldn’t attempt to unify effects recursively
- Updated the test suite to test against
polysemy-0.3
0.2.0.1 (2019-05-28)
- Fixed a bug where the plugin would get confused in the context of legitimate type errors
0.2.0.0 (2019-05-23)
- Fixed a serious bug where the changes from 0.1.0.1 broke most real-world usages of polysemy
- The plugin will now automatically perform the transformation in
polysemy
’sinlineRecursiveCalls
when run with-O
0.1.0.1 (2019-05-18)
- Added some explicit bounds for cabal
- Fixed a bug where effects that were too polymorphic would silently be accepted
0.1.0.0 (2019-04-27)
- Initial release
Unreleased changes
- Added
mapError