runST with Hindley-Milner type system

后端 未结 1 440
星月不相逢
星月不相逢 2021-02-15 05:03

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

相关标签:
1条回答
  • 2021-02-15 05:53

    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 () 
    ...
    
    0 讨论(0)
提交回复
热议问题