Skip to content

Removed ResourceT transformer / integrated into IO

Pre-release
Pre-release
Compare
Choose a tag to compare
@louthy louthy released this 16 May 09:37
· 2 commits to v5-transducers since this release

This release removes the ResourceT<M, A> monad-transformer from language-ext and instead moves the functionality into the IO<A> monad. ResourceT required IO to be in the transformer stack and so it really was adding complexity to a feature that's closely linked. This adds a tiny overhead to the IO monad -- the IO monad already carried an environment through its computations, so this doesn't change much -- in the big scheme of things it's likely to bring performance benefits.

Some big improvements because of this:

  • use and release are now available in the Prelude, which makes them easier to work with (no need for any manual generic arguments), everything is inferable from usage.
  • Forking an IO computation (launching it on a new thread) automatically creates a local resource environment for the fork and cleans it up when the forked operation is complete.
  • Repeating an IO computation (repeat(computation)) - will automatically clean up any resources acquired by use in the computation (on each iteration).
  • Retrying an IO computation (retry(computation)) - will automatically clean up any resources (acquired with use) when the computation fails, that mean retries don't accumulate resources unnecessarily.
  • New function local(computation) works as a 'super using' -- in that it will automatically clean up any resources acquired with use in the computation. This allows you to create local scopes where you just freely acquire resources and then have a clean-up happen automatically.
    • By the way, I am open to different names for this, as we already have IO.local for local cancellation contexts and Reader.local for local environments. I'm also open to changing the names of the others. Ideally any name would be a single word so it's easy on the eye. So, nothing like localResource or cleanUp.
  • New functions bracket(Acq, Use, Err, Fin) and bracket(Acq, Use, Fin) - these are like try \ catch \ finally blocks for more explicit resource usage:
    • Acq - acquires the resource
    • Use - uses the resource
    • Err - is the catch block
    • Fin - is the finally block

All the usual caveats apply: this is an alpha, this isn't fully tested, use at your own risk.