[Haskell-cafe] ANN: zoom-refs - zoom and pairing for mutable references

Marcin Mrotek marcin.jan.mrotek at gmail.com
Sun Jul 5 21:49:57 UTC 2015


I've just uploaded my package zoom-refs:

It's a "port" of State monad zoom (from lens) to mutable references:

    zoomTVar :: Lens' a b -> TVar a -> TVar b

These TVars aren't actually the raw TVars from STM, but wrappers that
provide the same functionality. Similar functions are provided for STRefs
and IORefs.

Additionally, TVars and STRefs can be paired to create composite references:

    pairTVars :: TVar a -> TVar b -> TVar (a,b)

No such functionality is provided for IORefs, as there would be no way to
guarantee atomicity of operations on the underlying references.

Together. mutable references can be used sort of like Functors and
Applicatives, though one needs to use lenses rather than plain functons to
map them. Finally, there are multiple references that use traversals
instead of lenses to zoom:

    readMultiTVar :: Monoid a -> MultiTVar a -> STM a

    readMultiTVarList :: MultiTVar a -> STM [a]

    readMultiTVarHead :: MultiTVar a -> STM (Maybe a)

Best regards,
Marcin Mrotek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150705/ac9b05f2/attachment.html>

More information about the Haskell-Cafe mailing list