Removed ResourceT transformer / integrated into IO
Pre-release
Pre-release
·
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
andrelease
are now available in thePrelude
, 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 byuse
in the computation (on each iteration). - Retrying an
IO
computation (retry(computation)
) - will automatically clean up any resources (acquired withuse
) when the computation fails, that mean retries don't accumulate resources unnecessarily. - New function
local(computation)
works as a 'superusing
' -- in that it will automatically clean up any resources acquired withuse
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 andReader.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 likelocalResource
orcleanUp
.
- By the way, I am open to different names for this, as we already have
- New functions
bracket(Acq, Use, Err, Fin)
andbracket(Acq, Use, Fin)
- these are liketry
\catch
\finally
blocks for more explicit resource usage:Acq
- acquires the resourceUse
- uses the resourceErr
- is the catch blockFin
- is the finally block
All the usual caveats apply: this is an alpha, this isn't fully tested, use at your own risk.