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


冉冉说
浏览 601回答 3
3回答

qq_笑_17

这种runST $ do { ... }模式非常普遍,而且通常不会进行类型检查,这一点令人讨厌,GHC包括一些ST特定的类型检查技巧以使其起作用。这些黑客可能会在此处触发该($)版本,而不是该(.)版本。

梦里花落0921

这些消息有点混淆了这一点(或者我感觉如此)。让我重写您的代码:runST (return True)   -- return True is ST s Bool(runST . return) True  -- cannot work另一种表达方式是单态m0 a0(如果返回a0,则返回结果)不能与(forall s.ST sa)统一。
打开App,查看更多内容
随时随地看视频慕课网APP