[Haskell-cafe] Stronger STM primitives needed? Or am I just doing
it wrong?
David Roundy
droundy at darcs.net
Wed Apr 23 15:25:56 EDT 2008
On Wed, Apr 23, 2008 at 12:12:15PM -0700, Ryan Ingram wrote:
> On 4/23/08, Jan-Willem Maessen <jmaessen at alum.mit.edu> wrote:
> > I've been trying to decide whether either of these is implementable in terms
> > of `orElse`, in such a way that we immediately check the predicate upon
> > retry before doing anything else. I can't quite make up my mind whether
> > this is possible or not.
>
> I do not think it is possible; consider this case:
>
> broken = atomically $ do
> v <- expensive_computation :: STM (TVar Int)
> retryUntil v (> 50)
>
> Given that you don't know which tvar to use until the end of the
> expensive computation, I don't see how you can lift "orElse" to the
> make that tvar be the first thing checked when the transaction is
> rerun.
I'm confused as to how your retryUntil gains you anything. If any of the
TVars used in the expensive_computation change while waiting for a retry,
then the expensive_computation will need to be done again. If none of them
change, then we can skip the expensive_computation. How does retryUntil
help us with this?
i.e. how does your broken function using retryUntil differ from the
following?
broken = atomically $ do
v <- expensive_computation :: STM (TVar Int)
vv <- readTVar v
unless (vv > 50) retry
--
David Roundy
Department of Physics
Oregon State University
More information about the Haskell-Cafe
mailing list