
On 05/07/2012 14:19, Favonia wrote:
Hi all,
Recently I am using amazing STM to program concurrent programs at ease. However I am puzzled by the type of STM.check. Currently it has the type "Bool -> STM a" and returns undefined when the input is True. I think it should have been "Bool -> STM ()" and returned () instead.
I couldn't image a situation that we need such generality in the type. Even worse, someone needs to write "void $ check x" or something to suppress warnings. In the paper "Beautiful Concurrency" the check function actually has the type "Bool -> STM ()". Thus, my question is, is there any good reason to have the type "Bool -> STM a" and to return undefined? If not, I am proposing this implementation (which is identical to the one in the Beautiful Concurrency):
check :: Bool -> STM () check b = if b then return () else retry
Good point; I'll change it. Thanks for the suggestion. Cheers, Simon