Patching STM

wren ng thornton wren at freegeek.org
Mon Feb 28 05:47:56 CET 2011


Hello all,

I have a number of functions and data structures I'd like to see added 
to the stm package. The package is listed as being maintained by the 
list, so I thought I'd ask how "sacred" stm is considered before going 
through the process to propose things.

The extra functions are no-brainers. Some are common conveniences (e.g., 
modifyTVar and modifyTVar'), some aim to make the API more consistent 
(e.g., add swapTVar like swapTMVar), and some can be optimized if 
they're included in the package (e.g., tryReadTMVar[1]).

The data structures are all variations on TChan which seem common enough 
to be included in the package, though I could also fork off a stm-data 
package instead. The variations include channels that can be closed, 
channels which have bounded depth (i.e., cause extra writes to block 
until room is available), and channels which are both bounded and closeable.

Thoughts? Also, to make proper patches, where is the stm repo?



[1] From outside the package we must define this as:

     tryReadTMVar :: TMVar a -> STM (Maybe a)
     tryReadTMVar var = do
         m <- tryTakeTMVar var
         case m of
             Nothing -> return ()
             Just x  -> putTMVar var x
         return m

Whereas, from inside the package we can just do:

     tryReadTMVar :: TMVar a -> STM (Maybe a)
     tryReadTMVar (TMVar t) = readTVar t

thus saving an extraneous read and write.

-- 
Live well,
~wren



More information about the Libraries mailing list