[Haskell-cafe] New STM Data Structures Collection

Ryan Yates fryguybob at gmail.com
Fri Oct 23 02:21:20 UTC 2015


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 <ok at cs.otago.ac.nz>
wrote:

> 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151022/7cc89d43/attachment.html>


More information about the Haskell-Cafe mailing list