Patching STM
Simon Peyton-Jones
simonpj at microsoft.com
Mon Feb 28 16:00:03 CET 2011
Not very sacred. Go ahead and propose.
http://darcs.haskell.org/packages/stm
S
| -----Original Message-----
| From: libraries-bounces at haskell.org [mailto:libraries-bounces at haskell.org] On
| Behalf Of wren ng thornton
| Sent: 28 February 2011 04:48
| To: libraries at haskell.org
| Subject: Patching STM
|
| 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
|
| _______________________________________________
| Libraries mailing list
| Libraries at haskell.org
| http://www.haskell.org/mailman/listinfo/libraries
More information about the Libraries
mailing list