New STM Data Structures Collection

Hi everyone! I want to present a couple of STM data structures which were implemented by me and Ryan Yates this summer (during GSOC 2015). I decided to create only a candidate package [1]. I would be glad if anyone can take a look and/or comment on topic. Since Hackage does not provide the easy way to `cabal install` candidate packages I have written a script [2] which should do all the work for you. It create a directory in /tmp and initialized sandbox along with cloning the library from github [3]. After that it will download Haskell program with an example of data structure usage. Thank you for your attention. [1] https://hackage.haskell.org/package/stm-data-collection-0.1.0.0/candidate [2] https://gist.github.com/Alllex/445f3d74e872fe032596 [3] https://github.com/Alllex/stm-data-collection -- Regards, Alex Semin

A suggestion after looking at the API docs: Usually modules called "Internal" are not meant to be used by the user of the library unless they really know what they're doing. However, the description of the package says that I should choose the implementation that suits my needs, so these aren't "Internal" modules after all. Also, they don't export anything that I would qualify as internal, such as data type constructors and helper functions. I'd suggest either renaming the "Internal" portion of the hierarchy to something else (such as "Impl") or dropping it completely (i.e., leaving the implementation modules on the same level as the "Class" modules). Everything else looks quite good! An advanced request would be having benchmarks showing which implementation is best for which use cases, esp. for [ALPRST]*SLPQ, but that's non-trivial. Cheers, :) -- Felipe.

Thanks! That's a reasonable suggestion. Actually the "Internal" module name was left there because we decided to export all implementation at the last moment. We've spent quite a lot of time working on benchmarks. Now you can find those which was ran on my laptop right in the github repo [1]. Although this kind of setting (I mean 4 capabilities) may not be the desired environment for STM-based algorithms. I believe we'll provide plots for machines with more capabilities in due course. Probably I had to include link to benchmarks into haddock package documentation. [1] https://github.com/Alllex/stm-data-collection/blob/master/charts/charts.pdf Thanks for your reply. On 22.10.2015 20:42, Felipe Lessa wrote:
A suggestion after looking at the API docs:
Usually modules called "Internal" are not meant to be used by the user of the library unless they really know what they're doing. However, the description of the package says that I should choose the implementation that suits my needs, so these aren't "Internal" modules after all. Also, they don't export anything that I would qualify as internal, such as data type constructors and helper functions.
I'd suggest either renaming the "Internal" portion of the hierarchy to something else (such as "Impl") or dropping it completely (i.e., leaving the implementation modules on the same level as the "Class" modules).
Everything else looks quite good! An advanced request would be having benchmarks showing which implementation is best for which use cases, esp. for [ALPRST]*SLPQ, but that's non-trivial.
Cheers, :)

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)

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

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
Note that this can also be written as maybeTake = optional . take where optional comes from Control.Applicative. -- Chris Wong (https://lambda.xyz) "I fear that Haskell is doomed to succeed." -- Tony Hoare
participants (7)
-
Alex Semin
-
Chris Wong
-
Felipe Lessa
-
Johannes Waldmann
-
Richard A. O'Keefe
-
Ryan Yates
-
Алексей Семин