Higher-order functions and ST

前端 未结 1 1054
慢半拍i
慢半拍i 2021-01-14 02:32

I\'m playing with http://hackage.haskell.org/packages/archive/vault/0.2.0.0/doc/html/Data-Vault-ST.html and want to write functions like the following:

onVau         


        
相关标签:
1条回答
  • 2021-01-14 02:44

    You need to give onVault and onVault2 rank 2 types.

    {-# LANGUAGE Rank2Types #-} -- RankNTypes would also work
    
    onVault :: (forall s. Key s a -> b) -> b
    onVault2 :: (forall s. Key s a -> Key s b -> c) -> c
    

    This is because runST :: (forall s. ST s a) -> a requires that the passed action is polymorphic in the state thread parameter s, which is a type-level trick used to guarantee purity. See the ST monad article on HaskellWiki for details.

    0 讨论(0)
提交回复
热议问题