# runST和函数组成

``runST \$ return \$ True` `

` `runST . return \$ True` `

GHCI抱怨：

` `Couldn't match expected type `forall s. ST s c0' with actual type `m0 a0' Expected type: a0 -> forall s. ST s c0 Actual type: a0 -> m0 a0 In the second argument of `(.)', namely `return' In the expression: runST . return` `

` `> :m + Control.Monad.ST > :set -XRankNTypes > :t (((.) :: ((forall s0. ST s0 a) -> a) -> (a -> forall s1. ST s1 a) -> a -> a) runST return) \$ True (((.) :: ((forall s0. ST s0 a) -> a) -> (a -> forall s1. ST s1 a) -> a -> a) runST return) \$ True :: Bool` `

` `> let app fx = fx > :t runST `app` (return `app` True) <interactive>:1:14: Couldn't match expected type `forall s. ST s t0' with actual type `m0 t10' Expected type: t10 -> forall s. ST s t0 Actual type: t10 -> m0 t10 In the first argument of `app', namely `return' In the second argument of `app', namely `(return `app` True)'` `

` `> :t (app :: ((forall s0. ST s0 a) -> a) -> (forall s1. ST s1 a) -> a) runST (return `app` True) (app :: ((forall s0. ST s0 a) -> a) -> (forall s1. ST s1 a) -> a) runST (return `app` True) :: Bool` `

` `(\$) :: forall p q. (p -> q) -> p -> q` `

` `runST \$ do ...` `

`runST \$ do { ... }`模式非常常见，而且通常不会进行types检查的事实非常令人讨厌，所以GHC包含了一些`ST`特定的types检查黑客来使其工作。 这些黑客可能在这里为`(\$)`版本，但不是`(.)`版本。

` `runST (return True) -- return True is ST s Bool (runST . return) True -- cannot work` `

Interesting Posts