3 ms·
Comprehensive Clojure STM Article
- jrockway 17y agoThey must ensure that no data that requires coordinated changes is modified outside an STM transaction. How does Clojure handle this? In Haskell, the type system ensures that STM operations can only happen where expected. (Reading a TMVar, for example, returns something of type STM (TMVar a). This means that the enclosing function must also return something of the type STM a. To get the actual data out, you run the transaction, which is of type STM a -> IO a. The type system automatically ensures that STM operations don't happen anywhere else.)
- cema 17y agoIn Clojure they require that all operations that affect STM are explicitly done inside a transaction, otherwise an error is raised.
- jrockway 17y agoI see, so it complains at runtime when when a transaction is not "in effect" and someone calls a transactional function?
- cema 17y agoYes, I believe it is correct. Keep in mind Clojure is running on top of jvm so they had to, first, figure out a balance between being practical and being "pretty" and, second, work within the constraints of the environment. I think Rich Hickey has done a tremendous job here (and keeps doing it).