cleff-plugin: Automatic disambiguation for extensible effects

[ bsd3, control, effect, language, library ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4.12 && <4.17), cleff (>=0.1 && <0.4), containers (>=0.5 && <0.7), ghc (>=8.6 && <9.3), ghc-tcplugins-extra (>=0.3 && <0.5) [details]
Tested with ghc ==8.6.5, ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2
License BSD-3-Clause
Copyright 2022 Xy Ren
Author Xy Ren
Maintainer xy.r@outlook.com
Category Control, Effect, Language
Home page https://github.com/re-xyr/cleff#readme
Bug tracker https://github.com/re-xyr/cleff/issues
Source repo head: git clone https://github.com/re-xyr/cleff
Uploaded by daylily at 2022-03-13T09:59:08Z
Distributions
Downloads 203 total (2 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for cleff-plugin-0.1.0.0

[back to package description]

cleff-plugin

This GHC typechecking plugin disambiguates obvious usages of effects for the extensible effect framework cleff.

Usage

This plugin works with GHC 8.6 through 9.2 and cleff >= 0.1 && < 0.4. To use the plugin:

  1. Add this plugin as your package's dependency.
    • If you use stack, then you also need to add these lines your stack.yaml:
      extra-deps:
      - cleff-plugin-0.1.0.0
      
  2. Enable the plugin by adding the following GHC option to your project file:
    ghc-options: -fplugin=Cleff.Plugin
    

What it does

When using cleff, the following code would not compile:

action :: '[State Int, State String] :>> es => Eff es ()
action = do
  x <- get
  put (x + 1)
-- • Could not deduce (Cleff.Internal.Rec.Elem (State s0) es)
--     arising from a use of ‘get’

This is because GHC is unable to determine which State effect we're trying to operate on, although the only viable choice is State Int. We had to write:

action :: '[State Int, State String] :>> es => Eff es ()
action = do
  x <- get @Int
  put (x + 1)

This is quite unwieldy. This plugin tells GHC extra information so code like this can typecheck without requiring manually annotating which effect to use.

References

This plugin's design is largely inspired by polysemy-plugin, which is in turn based on simple-effects.

Refer to docs/plugin-spec.md for details on the disambiguation algorithm this typecheck plugin uses.