If I understand the ST monad in Haskell correctly, runST
uses rank-2 types in a clever way to ensure that a computation does not reference any other thread when esc
Just in case the comments to the question are not entirely clear, the judgement you would need is
This is of course in conjunction with the other usual typing judgments that come with Hindley-Milner. Interestingly enough, we don't end up needing to make special rules for anything introducing an ST
type, since none of these require type signatures of rank 2:
newSTRef :: a -> ST s (STRef s a)
readSTRef :: STRef s a -> ST s a
writeSTRef :: STRef s a -> a -> ST s ()
...