
Hi Richard,
The isEmpty is not out of date as STM will detect if it is and restart the
transaction. The take operation will block if the bag is empty. If this
isn't clear in the documentation we should make it clearer. You can write
a maybeTake using orElse:
maybeTake b = (Just <$> take b) `orElse` return Nothing
Ryan
On Thu, Oct 22, 2015 at 8:27 PM, Richard A. O'Keefe
I'm really puzzled by the interface.
class Bag b where new :: STM (b v) -- no problem here add :: b v -> v -> STM () -- no problem here isEmpty :: b v -> STM Bool -- no real problem except the pervasive one that whatever -- you learn about the state of a concurrent object must -- always be treated as out of date when you use it take :: b v -> STM v -- what is supposed to happen if the bag is empty?
I was expecting an operation like
maybeTake :: b v -> STM (Maybe v)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe