scoped-codensity: CPS resource allocation but as a Monad and completely safe

[ agpl, control, library ] [ Propose Tags ] [ Report a vulnerability ]

This implements a Monad just like Codensity from the `kan-extensions` package, but it uses a skolem trap just like the `ST s` monad to track resources allocated in the monad. The package wraps around different "scoped" resources that cannot escape a scoped block and are safely deallocated when the block is left.


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
core

If set, only includes dependencies that are the bare minimum needed for this library

Disabled

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

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.2.0.0 (info)
Change log CHANGELOG.md
Dependencies async (<2.3), base (<5), temporary (<1.4), text (<2.2), transformers (<0.7), unliftio (<0.3), unliftio-core (<0.3) [details]
License AGPL-3.0-or-later
Author mangoiv
Maintainer contact@mangoiv.com
Category Control
Home page https://git.mangoiv.com/mangoiv/scoped-codensity
Uploaded by mangoiv at 2024-12-19T17:13:15Z
Distributions
Downloads 44 total (44 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 scoped-codensity-0.2.0.0

[back to package description]

ci hackage

scoped-codensity

This implements a Monad just like Codensity from the kan-extensions package, but it uses a skolem trap just like the ST s monad to track resources allocated in the monad.

The package wraps around different "scoped" resources that cannot escape a scoped block and are safely deallocated when the block is left.

How to make your own resources safe

  • for acquiring your resources:
    • use the bracketScoped function where possible
    • if you're using the raw UnsafeMkScoped constructor, make sure, the scope of your ScopedResource adheres to the scope you're in, by making your function return something of the shape Scoped (s : ss) m (ScopedResource s)
  • of working with your resources:
    • if you want to use the resource only in the same scope that it was created in, your function should be of the form: ScopedResource s -> ... -> Scoped (s : ss) m a
    • if you want to use the resource in the same scope and scopes that are contained within the scope (this is the more common option), relate the scope of the resource to the scopes of the Scoped monad, by specifying s :< ss like so: (s :< ss) => ScopedResource s -> .. -> Scoped ss m a
  • make sure that your actions are always in the Scoped monad and your resources always relate to the scopes that the monad is parametrized over, otherwise you might escape resources