heftia-effects: Handlers for standard effects using Heftia.

[ control, effect, library, monads, mpl, program ] [ Propose Tags ]

This library provides interpreters based on Heftia for the standard effect classes compliant with CEPs, offered by the classy-effects package.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],
Change log ChangeLog.md
Dependencies base (>= && <4.17), classy-effects (>=0.1 && <0.2), extensible (>=0.9 && <0.10), extra (>=1.7.14 && <1.8), ghc-typelits-knownnat (>=0.7 && <0.8), heftia (>=0.1 && <0.2), heftia-effects, loglevel (>=0.1.0 && <0.2), mtl (>=2.2.2 && <2.3), text (>=1.2.5 && <1.3), time (>=1.11.1 && <1.12), transformers (>=0.5.6 && <0.6) [details]
License MPL-2.0
Copyright 2023 Yamada Ryo
Author Yamada Ryo <ymdfield@outlook.jp>
Maintainer Yamada Ryo <ymdfield@outlook.jp>
Category Control, Effect, Monads
Bug tracker https://github.com/sayo-hs/heftia
Source repo head: git clone https://github.com/sayo-hs/heftia(tag v0.1.0)(heftia-effects)
Uploaded by YamadaRyo at 2023-09-18T06:41:34Z
Executables Writer, Continuation, Logging, Teletype
Downloads 50 total (13 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 heftia-effects-

[back to package description]


Heftia, a composition of hefty trees and co-Yoneda, is a higher-order effects version of Freer.

The paper

  • Casper Bach Poulsen and Cas van der Rest. 2023. Hefty Algebras: Modular Elaboration of Higher-Order Algebraic Effects. Proc. ACM Program. Lang. 7, POPL, Article 62 (January 2023), 31 pages. https://doi.org/10.1145/3571255

inspires this library. Hefty trees, proposed by the above paper, are extensions of free monads, allowing for a straightforward treatment of higher-order effects.

This library offers Heftia monads and Freer monads, encoded into data types in several ways to enable tuning in pursuit of high performance.

Additionally, it's designed to operate as a handler system based on classy-effects, which aims to standardize and unify the definitions of effects in Haskell.

Compared to existing Effect System libraries in Haskell that handle higher-order effects, this library's approach allows for a more effortless and flexible handling of higher-order effects. Here are some examples:

  • Two interpretations of the censor effect for Writer

    Let's consider the following Writer effectful program:

    hello :: (Writer String m, Monad m) => m ()
    hello = do
        tell "Hello"
        tell " world!"
    censorHello :: (Writer String m, Monad m) => m ()
    censorHello =
            (\s -> if s == "Hello" then "Goodbye" else s)

    For censorHello, should the final written string be "Goodbye world!"? Or should it be "Hello world!"? With Heftia, you can freely choose either behavior depending on which higher-order effect interpreter (which we call an elaborator) you use.

    main :: IO ()
    main = runFreerEffects do
        (s :: String, _) <-
                . runElaborate' (elaborateWriterT @String)
                $ censorHello
        (sTransactional :: String, _) <-
                . runElaborate' (elaborateWriterTransactionalT @String)
                $ censorHello
        sendIns $ putStrLn $ "Normal: " <> s
        sendIns $ putStrLn $ "Transactional: " <> sTransactional

    Using the elaborateWriterT elaborator, you'll get "Goodbye world!", whereas with the elaborateWriterTransactionalT elaborator, you'll get "Hello world!". For more details, please refer to the complete code and the implementation of the elaborator.

  • Extracting Multi-shot Delimited Continuations

    In handling higher-order effects, it's easy to work with multi-shot delimited continuations. This enables an almost complete emulation of "Algebraic Effects and Handlers". For more details, please refer to Example 3 - Delimited Continuation .

Furthermore, the structure of Heftia is theoretically straightforward, with ad-hoc elements being eliminated.

Heftia is the second objective of the Sayo Project.


Examples with explanations can be found in the docs/examples/ directory.

Future Plans

  • Benchmarking

  • Enriching the documentation

  • Completing missing definitions such as

    • the Heftia monad transformer encoded in tree structure
    • handlers for the Accum, Coroutine, Fresh, Input, Output effect classes

    and others.


The license is MPL 2.0. Please refer to the NOTICE. Additionally, this README.md and the documents under the docs/docs-ja directory are licensed under CC BY-SA 4.0.

Your contributions are welcome!

Please see CONTRIBUTING.md.