Why is it STintended to refuse the following code as shown in wikibook ? The article seems to suggest that the effects STwill flow in another STif it was allowed, but I really don't understand why.
It seems that I cannot run the specific one ST s (STRef s a). Are the STeffects contained and referenced transparent, but is such use still void?
Intuition tells me that there is a difference between semantics IOand STthat related to the fact that there is one IOand many independent ones 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
source
share