<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">As far as I understand you can call throwSTM and get desired effect.<div><br><br><div dir="ltr"><div><span style="font-size: 13pt;">—</span></div><div>Alexander Vershilov</div></div><div dir="ltr"><br><blockquote type="cite">29 нояб. 2020 г., в 00:07, amindfv--- via Haskell-Cafe <haskell-cafe@haskell.org> написал(а):<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><span>I'd like to be able to give up on an STM transaction: roll back and don't retry.</span><br><span>I've cooked up something with exceptions but it feels a bit icky to use exceptions for something like this - is there a better way?:</span><br><span></span><br><span> data Rollback = Rollback deriving (Show)</span><br><span> instance Exception Rollback</span><br><span></span><br><span> rollback :: STM x</span><br><span> rollback = throwSTM Rollback</span><br><span></span><br><span> atomicallyWithRollback :: STM x -> IO (Maybe x)</span><br><span> atomicallyWithRollback a =</span><br><span> (Just <$> atomically a)</span><br><span> `catch` (\Rollback -> pure Nothing)</span><br><span></span><br><span>The alternative I've found is something like:</span><br><span></span><br><span> otherWay :: STM x -> IO (Maybe x)</span><br><span> otherWay a =</span><br><span> atomically $ (Just <$> a) `orElse` pure Nothing</span><br><span></span><br><span>But this turns any "retry" in "a" into a rollback, and I'd like to have the option to do either (retry or rollback).</span><br><span></span><br><span>Thanks,</span><br><span>Tom</span><br><span></span><br><span></span><br><span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span>To (un)subscribe, modify options or view archives go to:</span><br><span>http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</span><br><span>Only members subscribed via the mailman list are allowed to post.</span></div></blockquote></div></body></html>