, - %%~, id. - , atomicModifyIORef (,) a Functor, . , , swappedId .
, Lens
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t
, f (,) a Functor, , , inc, , a . , :
import Data.IORef
import Control.Lens
l `swappedId` f = f & mapping swapped %~ l
main = do
let inc x = (x+1, x)
ior <- newIORef ((1, 1) :: (Int, Int))
thisShouldBe1 <- atomicModifyIORef ior $ _1 `swappedId` inc
print thisShouldBe1
print =<< readIORef ior