
On 2009 Feb 15, at 11:50, Peter Verswyvelen wrote:
I could try to read the article a couple of times again, but are there any other good readings about these existentially quantified types and how the ST monad works?
You could think about it as playing a dirty trick on the typechecker. The trick is that the scope of the forall-ed type is limited by the surrounding parentheses; therefore there is no way for the typechecker to know the type anywhere else, so it won't let you talk about it. Which means you can't use it outside the parentheses. Both the forall and the parentheses are necessary for this trick; if it were a concrete type, the typechecker knows it, and if it were a simple type variable its type would exist at the top level and therefore be available for type inference. The combination of the forall (which makes the type "slippery") inside the parentheses (which limits its scope) prevents top level type inference and leaves the compiler with no way to get at the type from outside, and if you can't get at the type you can't do anything with the value. The result is that the value is "trapped" inside the ST monad. If you try to use it you get the "escapes" error, which really means "I have no way to assign a type to this reference, so you can't touch it". -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH