This is an interesting idea, but the wrong way to go about it for at least a couple reasons. You'd lose some relationships you'd expect to hold:
(alter r identity) =/= r
(alter r f)(alter r f) =/= (alter r (comp f f))
(alter r f) =/= (ref-set r (f @r))
Also some transducers are side-effecting volatiles, and have no business in a dosync
block. i.e. if you use (take n)
as your transducer then if your dosync
fails, then it'll retry as though invoked with (take (dec n))
, which violates dosync
body requirements.
The problem is a ref
lets you read and write as separate steps. If instead there was something foundational that let you "apply" an input to a hidden "state" and collect the output all in one step, consistently with the STM, then that'd be something to work with.