As of r10528, the internal STM engine in the Haskell runtime is finally exposed to the userland:
my ($x, $y); async { atomically { $x = $y + 1; $y = $x + 1; } } for 1..5; say "($x, $y)" # Guaranteed to be (9, 10)
I'd like to thank nothingmuch++ for demanding -- and sponsoring -- this wonderful language feature. See the slides and this paper and another paper for more about STM. More exciting combinators such as orElse, retry and assert coming soon!
*bounces*
Posted by: nothingmuch | 2006.06.05 at 06:53 AM
Stick this stuff in the database! orElse!!
Posted by: Aristotle Pagaltzis | 2006.06.05 at 02:27 PM
is the above code "spec" perl6? is this limited to haskell? is it possible for this to manifest itself in the parrot support for perl6?
in any case, wow, over my head, but looks very cool.
Posted by: grumpY! | 2006.06.05 at 02:36 PM
grumpY: The "atomically" syntax is not specced down yet, but STM is likely to be part of Perl 6's concurrency model. And yes, one of the summer-of-code projects of perl.org this year is adding this support to Parrot.
Posted by: Audrey T | 2006.06.05 at 07:36 PM
Golly, I've barey even played with the non-haskell parts of pugs and not to any useful degree, but this fills my tummy with butterflies.
Posted by: ptolomy | 2006.06.05 at 11:07 PM
Interesting to see STM creeping in to Perl6. I'd like to know how Perl6 would prevent 'unsafe' IO taking place inside atomically blocks... but certainly looking forward to orElse and retry. =)
I do have reservations on how assert is implemented though -- it feels rather hacky in comparison with the rest of STM. (c.f. the original Haskell/STM paper, Composable Memory Transactions.) Haven't sat down long enough to work out the details of the alternative I'm thinking of...
Posted by: Liyang HU | 2006.06.16 at 08:08 AM
Liyang: Pugs prevents IO taking place by unifying IO and STM into the SIO monad, so any use of IO inside an atomic{} block is an exception. :-)
$ ./pugs -e 'atomically { say 1 }'
*** Unsafe IO caught in STM
at -e line 1, column 1-21
Posted by: Audrey T | 2006.06.16 at 03:12 PM
Hi Audrey,
Do you have anything written down about how STM works in Perl6? How closely does it follow the GHC implementation?
Also, what kinds of guarantees do you offer? Does the type system of Pugs mean that anything weaker or stronger is offered as compared with GHC?
I'd be interested to know, if any of this information has been abstracted from the implementation itself.
Thanks.
Posted by: | 2006.06.19 at 07:40 PM