Disambiguate obvious uses of effects. https://github.com/isovector/polysemy#readme

Version on this page:
Stackage Nightly 2019-06-17:
Latest on Hackage:

See all snapshots polysemy-plugin appears in

BSD-3-Clause licensed by Sandy Maguire
Maintained by sandy@sandymaguire.me

Module documentation for

This version can be pinned in stack with:polysemy-plugin-,2454


Build Status Hackage


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


A typechecker plugin that can disambiguate “obvious” uses of effects in polysemy.


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.


Add the following line to your package configuration:

ghc-options: -fplugin=Polysemy.Plugin


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


This plugin is copied almost verbatim from simple-effects.


Changelog for polysemy-plugin (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 (2019-05-28)

  • Fixed a bug where the plugin would get confused in the context of legitimate type errors (2019-05-23)

  • Fixed a serious bug where the changes from broke most real-world usages of polysemy
  • The plugin will now automatically perform the transformation in polysemy’s inlineRecursiveCalls when run with -O (2019-05-18)

  • Added some explicit bounds for cabal
  • Fixed a bug where effects that were too polymorphic would silently be accepted (2019-04-27)

  • Initial release

Unreleased changes

  • Added runErrorAsAnother
Used by 1 package in nightly-2019-06-09(full list with versions):
comments powered byDisqus