为什么ST设计为不允许使用wikibook中显示的以下代码? 文章似乎表明,如果允许, ST效应会泄漏到另一个ST ,但我不明白为什么。
看来我无法运行特定的ST s (STRef sa) 。 ST效应是否包含并且是引用透明的,但是这种使用仍被认为是无效的?
直觉告诉我, IO和ST语义之间存在着差异,因为有一个IO和许多独立的ST ,但我不确定。
> runST (newSTRef True) <interactive>:5:8: error: • Couldn't match type ‘a’ with ‘STRef s Bool’ because type variable ‘s’ would escape its scope This (rigid, skolem) type variable is bound by a type expected by the context: forall s. ST s a at <interactive>:5:1-21 Expected type: ST s a Actual type: ST s (STRef s Bool) • In the first argument of ‘runST’, namely ‘(newSTRef True)’ In the expression: runST (newSTRef True) In an equation for ‘it’: it = runST (newSTRef True) • Relevant bindings include it :: a (bound at <interactive>:5:1) > :t newSTRef newSTRef :: a -> ST s (STRef s a) > :t runST runST :: (forall s. ST s a) -> aWhy is ST designed to disallow the following code as shown in the wikibook? The article seems to suggest that ST effects would leak into another ST if this was allowed, but I don't really understand why.
It seems that I cannot run a specific ST s (STRef s a). Are ST effects contained and referentially transparent, but such use is still considered invalid?
Intuition tells me that there is difference between semantics of IO and ST related to that there is one IO and many independent ST, but I'm not sure.
> runST (newSTRef True) <interactive>:5:8: error: • Couldn't match type ‘a’ with ‘STRef s Bool’ because type variable ‘s’ would escape its scope This (rigid, skolem) type variable is bound by a type expected by the context: forall s. ST s a at <interactive>:5:1-21 Expected type: ST s a Actual type: ST s (STRef s Bool) • In the first argument of ‘runST’, namely ‘(newSTRef True)’ In the expression: runST (newSTRef True) In an equation for ‘it’: it = runST (newSTRef True) • Relevant bindings include it :: a (bound at <interactive>:5:1) > :t newSTRef newSTRef :: a -> ST s (STRef s a) > :t runST runST :: (forall s. ST s a) -> a最满意答案
对问题标题的回答多于问题本身,但仍然是:
是的,ST是透明的。
很长一段时间,这只是猜测和相信,只有今年我们有一个适当的证据:
Monadic封装状态的逻辑关系:在runST存在的情况下证明上下文等价 Amin Timany,LéoStefanesco,Morten Krogh-Jespersen,Lars Birkedal 有条件地接受POPL 2018 http://iris-project.org/ 预印PDF
More an answer to the question title than the question itself, but still:
Yes, ST is referentially transparent.
For a long time this was just conjectured and believed, and only this year we have a proper proof for that:
A Logical Relation for Monadic Encapsulation of State: Proving contextual equivalences in the presence of runST Amin Timany, Léo Stefanesco, Morten Krogh-Jespersen, Lars Birkedal Conditionally accepted to POPL 2018 http://iris-project.org/ Preprint PDF
ST的指纹是透明的吗?(Is ST referentialy transparent?)为什么ST设计为不允许使用wikibook中显示的以下代码? 文章似乎表明,如果允许, ST效应会泄漏到另一个ST ,但我不明白为什么。
看来我无法运行特定的ST s (STRef sa) 。 ST效应是否包含并且是引用透明的,但是这种使用仍被认为是无效的?
直觉告诉我, IO和ST语义之间存在着差异,因为有一个IO和许多独立的ST ,但我不确定。
> runST (newSTRef True) <interactive>:5:8: error: • Couldn't match type ‘a’ with ‘STRef s Bool’ because type variable ‘s’ would escape its scope This (rigid, skolem) type variable is bound by a type expected by the context: forall s. ST s a at <interactive>:5:1-21 Expected type: ST s a Actual type: ST s (STRef s Bool) • In the first argument of ‘runST’, namely ‘(newSTRef True)’ In the expression: runST (newSTRef True) In an equation for ‘it’: it = runST (newSTRef True) • Relevant bindings include it :: a (bound at <interactive>:5:1) > :t newSTRef newSTRef :: a -> ST s (STRef s a) > :t runST runST :: (forall s. ST s a) -> aWhy is ST designed to disallow the following code as shown in the wikibook? The article seems to suggest that ST effects would leak into another ST if this was allowed, but I don't really understand why.
It seems that I cannot run a specific ST s (STRef s a). Are ST effects contained and referentially transparent, but such use is still considered invalid?
Intuition tells me that there is difference between semantics of IO and ST related to that there is one IO and many independent ST, but I'm not sure.
> runST (newSTRef True) <interactive>:5:8: error: • Couldn't match type ‘a’ with ‘STRef s Bool’ because type variable ‘s’ would escape its scope This (rigid, skolem) type variable is bound by a type expected by the context: forall s. ST s a at <interactive>:5:1-21 Expected type: ST s a Actual type: ST s (STRef s Bool) • In the first argument of ‘runST’, namely ‘(newSTRef True)’ In the expression: runST (newSTRef True) In an equation for ‘it’: it = runST (newSTRef True) • Relevant bindings include it :: a (bound at <interactive>:5:1) > :t newSTRef newSTRef :: a -> ST s (STRef s a) > :t runST runST :: (forall s. ST s a) -> a最满意答案
对问题标题的回答多于问题本身,但仍然是:
是的,ST是透明的。
很长一段时间,这只是猜测和相信,只有今年我们有一个适当的证据:
Monadic封装状态的逻辑关系:在runST存在的情况下证明上下文等价 Amin Timany,LéoStefanesco,Morten Krogh-Jespersen,Lars Birkedal 有条件地接受POPL 2018 http://iris-project.org/ 预印PDF
More an answer to the question title than the question itself, but still:
Yes, ST is referentially transparent.
For a long time this was just conjectured and believed, and only this year we have a proper proof for that:
A Logical Relation for Monadic Encapsulation of State: Proving contextual equivalences in the presence of runST Amin Timany, Léo Stefanesco, Morten Krogh-Jespersen, Lars Birkedal Conditionally accepted to POPL 2018 http://iris-project.org/ Preprint PDF
发布评论