@hackage scoped-codensity0.2.0.0

CPS resource allocation but as a Monad and completely safe

  • Installation

  • Dependencies (7)

  • Dependents (0)

  • Package Flags

      core
       (off by default)

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

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