polysemy-plugin: Disambiguate obvious uses of effects.

[ bsd3, library, polysemy ] [ Propose Tags ] [ Report a vulnerability ]

Flags

Manual Flags

NameDescriptionDefault
corelint

Perform the corelint tests

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0, 0.1.0.1, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.2.0.3, 0.2.1.0, 0.2.1.1, 0.2.2.0, 0.2.3.0, 0.2.4.0, 0.2.5.0, 0.2.5.1, 0.2.5.2, 0.3.0.0, 0.4.0.0, 0.4.1.0, 0.4.1.1, 0.4.2.0, 0.4.3.0, 0.4.3.1, 0.4.4.0, 0.4.5.0, 0.4.5.1, 0.4.5.2 (info)
Change log ChangeLog.md
Dependencies base (>=4.9 && <5), containers (>=0.5 && <0.8), ghc (>=8.6.5 && <10), ghc-tcplugins-extra (>=0.3 && <0.5), polysemy (>=1.7), syb (>=0.7 && <0.8), transformers (>=0.5.2.0 && <0.7) [details]
License BSD-3-Clause
Copyright 2019 Sandy Maguire
Author Sandy Maguire
Maintainer sandy@sandymaguire.me
Revised Revision 1 made by tek at 2024-10-28T13:11:13Z
Category Polysemy
Home page https://github.com/polysemy-research/polysemy#readme
Bug tracker https://github.com/polysemy-research/polysemy/issues
Source repo head: git clone https://github.com/polysemy-research/polysemy
Uploaded by tek at 2023-12-29T13:30:35Z
Distributions LTSHaskell:0.4.5.2, NixOS:0.4.5.2, Stackage:0.4.5.2
Reverse Dependencies 50 direct, 16 indirect [details]
Downloads 11295 total (51 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for polysemy-plugin-0.4.5.2

[back to package description]

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.