polysemy/polysemy-plugin
Samuel Evans-Powell 95b4b5508c Feature/cabal doctest and ghc 8.8.1 (#267)
* Use cabal-doctest

- Haskell build tools run in slightly different environments (meaning different
  package databases are available).
- The nixpkgs build for polysemy-plugin is failing due to a missing package
  database, which causes the doctest to fail (more information here:
  https://github.com/NixOS/nixpkgs/issues/71164).
- By using cabal-doctest we can expose the Haskell packages required to the
  doctests no matter the build tool we're using.

* Use cabal-doctest in polysemy, build on GHC 8.8.1

- Use @googleson78 's changes to build polysemy on GHC 8.8.1, with slight
  modifications. The source distribution is now found in "dist-newstyle/sdist",
  so we've updated the command to point at that folder. Additionally, cabal
  v2-install doesn't support installing .tar.gz files in the same way v1-install
  did, so updated the command to use "cabal v1-install".
- Modified polysemy to use "cabal-doctest" and so overcome issues with the
  doctest tests (see issue #258, PR #265).
2019-10-28 17:13:44 +01:00
..
src/Polysemy Give a better error if polysemy can't be loaded by the plugin 2019-10-23 15:48:08 +02:00
test Feature/cabal doctest and ghc 8.8.1 (#267) 2019-10-28 17:13:44 +01:00
.gitignore Release polysemy-plugin-0.2.0.0 2019-05-23 17:06:24 -04:00
ChangeLog.md Release polysemy-plugin-0.2.3.0 2019-09-04 11:19:39 -07:00
LICENSE plugin 2019-04-20 18:31:17 -04:00
package.yaml Run core-lint on the plugin tests 2019-10-09 14:51:03 +02:00
polysemy-plugin.cabal Feature/cabal doctest and ghc 8.8.1 (#267) 2019-10-28 17:13:44 +01:00
README.md Fix plugin badge 2019-06-26 10:23:06 -04:00
Setup.hs Feature/cabal doctest and ghc 8.8.1 (#267) 2019-10-28 17:13:44 +01:00

polysemy-plugin

Build Status Hackage

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.