為什么要進行此類型檢查:runST $ return $ True盡管以下內(nèi)容沒有:runST . return $ TrueGHCI抱怨: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 a0In the second argument of `(.)', namely `return'In the expression: runST . return
3 回答

qq_笑_17
TA貢獻1818條經(jīng)驗 獲得超7個贊
這種runST $ do { ... }
模式非常普遍,而且通常不會進行類型檢查,這一點令人討厭,GHC包括一些ST
特定的類型檢查技巧以使其起作用。這些黑客可能會在此處觸發(fā)該($)
版本,而不是該(.)
版本。

夢里花落0921
TA貢獻1772條經(jīng)驗 獲得超6個贊
這些消息有點混淆了這一點(或者我感覺如此)。讓我重寫您的代碼:
runST (return True) -- return True is ST s Bool
(runST . return) True -- cannot work
另一種表達方式是單態(tài)m0 a0(如果返回a0,則返回結(jié)果)不能與(forall s.ST sa)統(tǒng)一。
添加回答
舉報
0/150
提交
取消