STM.check should have type Bool -> STM ()

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 Thank fryguybob on the IRC for discussing with me. There's only a SO question on this: http://stackoverflow.com/q/8364903. By the way, STM.check seems to be the only undocumented API in the stm package. :-P Thanks, Favonia

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
participants (2)
-
Favonia
-
Simon Marlow